Reputation: 13055
I uses the following line of code to define a multi-dimensional array to save a set of images represented as two-dimensional array as well.
import numpy as np
imgs = np.ndarray((100, 1, image_rows, image_cols), dtype=np.float32)
Here, 100
represents that there have 100 images in total.
However, running the program gives the following error message TypeError: 'float' object cannot be interpreted as an integer
. What does it mean and how to solve it?
Upvotes: 2
Views: 4717
Reputation: 114946
You will get that error if image_rows
or image_cols
are floating point values:
In [15]: imgs = np.ndarray((100, 1, 5.0, 10.0), dtype=np.float32)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-c7783d157b42> in <module>()
----> 1 imgs = np.ndarray((100, 1, 5.0, 10.0), dtype=np.float32)
TypeError: 'float' object cannot be interpreted as an integer
Convert the values to integers first:
imgs = np.ndarray((100, 1, int(image_rows), int(image_cols)), dtype=np.float32)
Upvotes: 1