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]]

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)
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

Comments

Your Answer

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.