2

I have an array saved in a npy file and want to export it into readable text columns.

The array is here: https://drive.google.com/open?id=1DErx4e0NBJJNxixMSuGQaahdAcGX7jkI

I did the following:

import numpy as np
data = np.load('D:/20190805_01_data.npy')

type(data) gives numpy.ndarray

len(data) gives 1363

data.ndim gives 3

To export data I tried:

np.savetxt('D:/data.txt',data, delimiter=' ')

which does not work.

What is the correct solution?

Rory Daulton
  • 21,934
  • 6
  • 42
  • 50
lio
  • 145
  • 1
  • 6
  • what is the output op np.savetxt? – WiseDev Aug 05 '19 at 11:26
  • I looked here: https://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html. The output should be a text file containing columns. – lio Aug 05 '19 at 11:29
  • Sorry I was unclear. I do not mean to ask what the output is *supposed* to be, rather I wish to ask what *your current output* is. – WiseDev Aug 05 '19 at 11:30
  • 2
    How do you want to represent 3d (`data.ndim = 3`) data in a simple text file? There are only two dimensions (rows and columns). The `function np.savetxt`supports only 1d or 2d data according to the documentation. – MofX Aug 05 '19 at 11:30
  • @MofX: I thought there are 1363 lines with 2 coumns, when I check e.g. `data[1::5]`. – lio Aug 05 '19 at 11:35
  • @lio `data.ndim` == 3 means that you have a 3-dimensional array. You can check this post on how to write multidimensional data into a txt file: https://stackoverflow.com/questions/3685265/how-to-write-a-multidimensional-array-to-a-text-file – Gonzalo Hernandez Aug 05 '19 at 11:39
  • 1363 lines with 2 columns would be a two dimensional array -> `ndim = 2`. I did not look at your source file, because I don't really like downloading and evaluating it. – MofX Aug 05 '19 at 11:40
  • @MofX: Where should I upload the file, so that somebody can check it? – lio Aug 05 '19 at 11:54
  • You should have told us the `shape` initially. It would have saved a lot of questions. – hpaulj Aug 05 '19 at 14:46

1 Answers1

2

it seems that your data have one extra dimension

data.shape
Out[4]: (1363, 1, 2)

You can do the following to remove this dimension :

data = np.squeeze(data)

and then save data to a .txt file.

Adakor
  • 65
  • 6