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
Majesty Eksa Permana
812 silver badges6 bronze badges
2 Answers 2
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
Avinash Raj
175k32 gold badges247 silver badges289 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Majesty Eksa Permana
Thx for your answer Avinash Raj, :)
try this
...
...
z = []
for i in range(len(s)):
z.append((s[i]-mean)/stdev)
print z
answered Mar 28, 2015 at 4:10
splucena
3833 gold badges8 silver badges17 bronze badges
Comments
lang-py