Python:Numpy dtype U32-简单if-else语句
我不理解numpy数组的以下行为。给定以下数组f:Python:Numpy dtype U32-简单if-else语句,python,arrays,numpy,Python,Arrays,Numpy,我不理解numpy数组的以下行为。给定以下数组f: array([u'1.8', u'1.8', u'2.4', u'2.2', u'2.0', u'2.1', u'2.8', u'3.2', u'3.3', u'3.4', u'2.8'], dtype='<U32') for a in f: if a > 2.2: print "greater" else: print "smaller" 数组([u'1.8',u'
array([u'1.8', u'1.8', u'2.4', u'2.2', u'2.0', u'2.1', u'2.8', u'3.2',
u'3.3', u'3.4', u'2.8'], dtype='<U32')
for a in f:
if a > 2.2:
print "greater"
else:
print "smaller"
数组([u'1.8',u'1.8',u'2.4',u'2.2',u'2.0',u'2.1',u'2.8',u'3.2',
u'3.3',u'3.4',u'2.8'],dtype='这是因为数组中的值是Unicode字符串,而不是整数。在python
中,数字类型在比较时总是比非数字类型“大”。有关更深入的解释,请参阅
要获得您想要的功能,您需要将字符串转换为数字。这是因为数组中的值是Unicode字符串,而不是整数。在python
中,数字类型在比较时总是比非数字类型“大”。有关更深入的解释,请参阅
要获得您想要的功能,您需要将字符串转换为数字。为什么数组包含字符串而不是数字
?为什么数组包含字符串而不是数字
?