0

I have a problem to split array into array, here the source code and the output,

import numpy as np
s = np.array([[100], [200], [300], [400], [500]])
mean = np.mean(s)
stdev = s.std()
for i in range(len(s)):
 z = ((s[i]-mean)/stdev)
 print z

out :

[-1.41421356]
[-0.70710678]
[ 0.]
[ 0.70710678]
[ 1.41421356]

I want the output like this :

[[-1.41421356]
[-0.70710678]
[ 0.]
[ 0.70710678]
[ 1.41421356]]
asked Mar 28, 2015 at 4:05

2 Answers 2

1

Create an empty list and then append the results to that empty list.

import numpy as np
s = np.array([[100], [200], [300], [400], [500]])
mean = np.mean(s)
stdev = s.std()
x = []
for i in range(len(s)):
 x.append(((s[i]-mean)/stdev))
print np.array(x)
answered Mar 28, 2015 at 4:07
Sign up to request clarification or add additional context in comments.

1 Comment

Thx for your answer Avinash Raj, :)
0

try this

...
...
z = []
for i in range(len(s)):
 z.append((s[i]-mean)/stdev)
print z
answered Mar 28, 2015 at 4:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.