I have encountered an error while trying to write a numpy error into a text file. To put the question the below code
import numpy as np
a = np.arange(1,10)
sigma = open("sample",'w')
for row in a:
np.savetxt(sigma,row)
sigma.close()
gives an error ValueError: Expected 1D or 2D array, got 0D array instead
I worked around it with this code:
a = np.arange(1,10)
sigma = open("sample",'w')
np.savetxt(sigma,a, newline="\n")
sigma.close()
But I still do not now why my first attempt didn't work. Why my array appears 0D? (I'm using python 3.9.9)
ais 1-dimensional. It does not have rows.ais 1-d, butrowis 0-d.