Python:float()参数必须是字符串或数字

Python:float()参数必须是字符串或数字,python,numpy,matplotlib,Python,Numpy,Matplotlib,我需要将图像加载到阵列中。然后我想用pyplot来显示它。问题就在两者之间 我尝试了不同类型的imread。我只安装了pyplot中导致问题的一个 import numpy as np from matplotlib.pyplot import imread images = [] img = imread('1.png') img = np.array(img.resize(224,224)) images.append(img) images_arr = np.asarray(image

我需要将图像加载到阵列中。然后我想用pyplot来显示它。问题就在两者之间

我尝试了不同类型的imread。我只安装了pyplot中导致问题的一个

import numpy as np
from matplotlib.pyplot import imread

images = []
img = imread('1.png')
img = np.array(img.resize(224,224))
images.append(img)

images_arr = np.asarray(images)
images_arr = images_arr.astype('float32')

plt.figure(figsize=[5, 5])
curr_img = np.reshape(images_arr[0], (224,224))
plt.imshow(curr_img, cmap='gray')
plt.show()
有一个错误:

images_arr = images_arr.astype('float32')
TypeError: float() argument must be a string or a number, not 'NoneType'
调整数据的大小并返回
None
。不要使用返回值创建数组,直接使用
img
。它已经是一个numpy阵列:

如果需要数据的副本,请使用`:

请注意,
matplotlib.pyplot.imread()
函数只不过是的别名。

调整数据大小并返回
None
。不要使用返回值创建数组,直接使用
img
。它已经是一个numpy阵列:

如果需要数据的副本,请使用`:

请注意,
matplotlib.pyplot.imread()
函数只不过是的别名

img = imread('1.png')
img.resize(224,224)  # alters the array in-place, returns None
images.append(img)   # so just use the array directly.
img = imread('1.png')
resized_img = np.resize(img, (224,224))
images.append(resized_img)