2

I try to display a numpy file, then display its correct length, I put my file in folder:

import numpy as np
import os
path= "C:\\Users\\user\\Folder"
files= os.listdir(path)
filepath= os.path.join(path, files[0])
file0= np.load(filepath)
print(file0)
print (len(file0))

The result is an imbrication of tables, which gives me as length=1 instead of length=8000 :

[[ 0.01437869  0.01506449  0.01579909 ...,  0.04166172  0.0417285
   0.04172079]]

1

But I need to have is:

[ 0.01437869  0.01506449  0.01579909 ...,  0.04166172  0.0417285
   0.04172079]

8000

How to resolve this problem please.

3
  • 1
    Use .ravel() or np.squeeze(). Commented Apr 27, 2017 at 9:50
  • 2
    and have a look at .shape instead of len(). Commented Apr 27, 2017 at 9:52
  • Looks like the true file0.shape is (1,8000). Commented Apr 27, 2017 at 12:33

1 Answer 1

3

This should work:

file0= np.load(filepath)[0]
Sign up to request clarification or add additional context in comments.

1 Comment

I like this syntax to unpack single item sequences better, but YMMV: file0, = np.load(filepath).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.