hi all,

I want to write ndarray to excel file and then want to plot a graph, i m getting an error that my ndarray is 32d and required one is 1 dimension or 2 dimension to write into excel file.I m not able to convert 32d nd array to 1d or 2d, neither able to write it on excel sheet.

Any suggestion ?? pls help.

Hi @dimple,

Do you want to write an NDArray of shape `(32, n)`

or `(dim0, dim1, ..., dim31)`

?

Can you give us a link or paste the snippet and the error?

hi spanev,

i m having ndarray of this type,

[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[

[-1]

<NDArray 1 @cpu(0)>]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

When i m trying to write this on excel file using “np.savetxt(‘one.csv’,knee_angle,delimiter=’,’, fmt=’%darray’)” then getting this error:

“Expected 1D or 2D array, got %dD array instead” % X.ndim)

ValueError: Expected 1D or 2D array, got 32D array instead"

Thanks

how about `array.squeeze()`

? https://mxnet.incubator.apache.org/api/python/ndarray/ndarray.html#mxnet.ndarray.squeeze

hi olivcruche,

thanks , bt when using “np.squeeze(knee_angle,axis=(0,1))”, getting this error,

“Expected 1D or 2D array, got %dD array instead” % X.ndim)

ValueError: Expected 1D or 2D array, got 30D array instead.

Or when using ,“np.squeeze(knee_angle)”

“Expected 1D or 2D array, got %dD array instead” % X.ndim)

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

Or when using ,np.savetxt(‘g.csv’,mx.ndarray.squeeze(knee_angle),delimiter=’,’, fmt=’%darray’)

Getting this error, print(mx.ndarray.squeeze(knee_angle))

File “”, line 39, in squeeze

AssertionError: Positional arguments must have NDArray type, but got [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[

[-1]

<NDArray 1 @cpu(0)>]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

please help !! i need to plot graph for knee_angle.

could you write here the format of the array? I see

`[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[-1]<NDArray 1 @cpu(0)>]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]`

above so are you trying to save a single number to excel?

@hi olivier

actually its just a dummy value , that i have calculated for knee_angle in radian(for static image). This is the format(stated above) in which i m getting my data, want to convert this into 1d or 2d so i can write it in my excel sheet.

Further i will be having so many knee_angle values, that need to be stored in excel sheet.

First i want to write this data on excel , but getting an error.

ok, turned out the command you need is a `.flatten()`

. Find below a working test I did with an array that has the above-provided shape:

```
import mxnet as mx
from mxnet import ndarray as nd
import pandas as pd
# create 32d nested single-value array
knee = nd.array([-1])
for _ in range(31):
knee = knee.expand_dims(axis=0)
print(knee)
# save to excel through numpy and pandas
pd.DataFrame(knee.flatten().asnumpy()).to_excel('data.xlsx') # save with index and columns header
pd.DataFrame(knee.flatten().asnumpy()).to_excel('data_raw.xlsx', index=False, header=None) # save only the value
```

Thank you @olivcruche, with few changes i m able to save that.

bt how to append data in already existing file.

pd.DataFrame(knee.flatten().asnumpy()).to_excel(‘data.xlsx’), what changes should i made in this.

Thank you