Py学习  »  Python

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

gragas01 • 5 年前 • 1718 次点击  

我需要将图像加载到数组中。然后我想用pyplot来展示。这个问题介于两者之间。

我试过不同类型的阅读。我只安装了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'
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/49465
 
1718 次点击  
文章 [ 1 ]  |  最新文章 5 年前