justStarting
justStarting

Reputation: 129

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

I am trying to export array that I created to ".csv" file but I am getting an error from a title.

I create array with:

map_table = np.zeros((broj_stanja, broj_akcija)) #(500 x 6)

My export code:

np.savetxt("test.csv", map_table, delimiter=",")

Array looks like:

[[0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0.]
 ...
 [0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0.]]

And filled array looks like:

[[  0.           0.           0.           0.           0.
    0.        ]
 [ -2.32127743  -2.13656866  -2.32039787  -2.13702084  -1.83910189
  -11.1362683 ]
 [ -1.84018441  -1.35777159  -1.83913505  -1.36492166  -0.57891593
  -10.35787171]
 ...
 [ -2.13231639  -1.35809409  -2.06537874  -2.17259228 -10.74950563
  -10.88689193]

Full code example.

Upvotes: 2

Views: 4353

Answers (1)

zipa
zipa

Reputation: 27869

Saving a function returns such error:

def ucenje():
   return np.array((1, 1, 1))
np.savetxt('test.txt', ucenje)

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

Take note that an empty file is created on disc.

Upvotes: 2

Related Questions