lee.edward01
lee.edward01

Reputation: 473

python/numpy ValueError: Expected 1D or 2D array, got 0D array instead

I was trying to add the individual rows of my array which I changed from a dataframe, and after adding all the rows, I was trying to save the array into a csv file and I get this error: Expected 1D or 2D array, got 0D array instead. My code where I believe the problem lies is below:

array = dfmain.values
shareArray = array[:1]
shareArray = dividedPV/shareArray
array = shareArray * array
sums = [sum(j) for j in array]
finalArray = np.array(sums, dtype=np.float16) #tried to change it from list to Array to see if that was the problem



#changes the file name to whatever the variables (portname etc) were given above
filename = "calculated_%s_%s_%s.csv" % (portName, inceptionDate, frequency)
np.savetxt("%s.csv", filename, finalArray, delimiter = ",")

Any tips would be greatly appreciated!

Upvotes: 4

Views: 23335

Answers (1)

cuuupid
cuuupid

Reputation: 1002

The first argument of np.savetxt is the filename; you have two filenames as arguments and the actual array to be saved as the third argument, it should be the second.

i.e.

np.savetxt(filename, finalArray, delimiter=',')

Upvotes: 2

Related Questions