[英]Numpy array declaration error
我编写了以下代码以从图像中提取特征。 一旦从featex函数中提取出特征向量,就需要将其附加到一个大型特征2D数组中,该数组包含用于训练的所有图像的特征。 代码如下:
for dirs, path, files in os.walk("wallet_training/"):
for filename in files:
f=os.path.join("wallet_training",filename)
I=Image.open("wallet_training/1(1).jpeg")
I=imresize(I,(256,256))
p=featex(I)
features=np.vstack([features],[p])
print features.shape
它给出以下错误:
NameError: name 'features' is not defined
有人可以帮我为什么会出现此错误,因为据我所知,python中的变量不需要事先定义。
先感谢您。
正如其他用户在评论中建议的那样,您需要声明features
。
另外,我建议您使用Python列表添加数据,然后转换为numpy数组:
features = [];
for dirs, path, files in os.walk("wallet_training/"):
for filename in files:
f=os.path.join("wallet_training",filename)
I=Image.open("wallet_training/1(1).jpeg")
I=imresize(I,(256,256))
p=featex(I)
features.append(p) #'features' is a Python list
features = np.array(features)#Now 'features' is an array
print features.shape
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.