1

I have the following Python script portion:

X_to_text_file = np.savetxt('x.txt', X.reshape(np.shape(X)), fmt='%5f')

for which I'm getting this error:

AttributeError: 'list' object has no attribute 'reshape'

Provided that X is a Numpy array, which I obtained as follows:

for img in range(len(names)):
    for name in names:
        img = np.array(Image.open(name))
        X.append(img)

Any ideas why I'm getting this error and how I can solve it?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385

1 Answers1

-1

I see two problems here. First, your snippet is incomplete, as there is no definition of X. Without it, in minimal example, you'd see something like:

>>> import numpy as np
>>> X.append(np.array())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'X' is not defined

So, you had to create X somewhere before, and judging by your error message, it's a plain Python list.

Now, on how to join numpy arrays together, I think this answer will help you out.

zencodism
  • 442
  • 4
  • 9