I am trying to produce random number by random.normal
and take the summary of them. Then, I tried to assgin the value to each element in the array sum
.
I made a zero array (float type) by np.zeros
and then assign the value in following way.
I attempted to utilize numpy and matlibplot.pyplot as libraries to do this.
My code:
np.random.seed(0)
sum=np.zeros(10,dtype=float)
for i in np.arange(1,11):
X = np.random.normal(size=(10,1))
Y=np.sum(X,axis=1)
sum[i-1]=Y
print(sum)
When I conduct this code on Google Colab, following errors happened.
TypeError Traceback (most recent call last)
TypeError: only size-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
<ipython-input-14-33fba8ac5d90> in <module>
6 X = np.random.normal(size=(10,1))
7 Y=np.sum(X,axis=1)
----> 8 sum[i-1]=Y
9 print(sum)
ValueError: setting an array element with a sequence.
Could you please tell me how to solve this error?