ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.al
2018-03-08 11:10
711 查看
解决方案
本文中的解决方法,只限于一部分问题,可能不通用。因为楼主在跑python代码时经常遇到这个问题,以前是怎么解决的都已经忘记了,今天又查了一大通,故记录下来:training_examples["latitude_0_to_35"]=1 if (training_examples["latitude"]>=0 and training_examples["latitude"]<=35) else 0 # 想用这样的赋值语句,结果报错了(PS: training_examples是dataframe类型) ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
故想实现上面的方法,改用如下方案:
training_examples["latitude_0_to_35"]= (training_examples["latitude"]>=0) & (training_examples["latitude"]<=35) # 此处用 & 应该是因为training_examples["latitude"]存在多个value值,得“按位”比较。如果是单纯的数值用and就是可以的,可见最后的例子。 training_examples["latitude_0_to_35"] = training_examples["latitude_0_to_35"].astype('int') #这一步是将得到的true和false转化为1和0,直接bool型变为int型 IN: a = 1 if (3>2 and 4>3) else 0 IN: a OUT: 1
相关文章推荐
- Python-numpy逻辑报错:The truth value of an array with more than one element is ambiguous. Us
- Python-numpy逻辑报错:The truth value of an array with more than one element is ambiguous
- How to limit an array of similar hashes to those that have more than one of the same key:value pair
- The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You mu
- The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You mu
- 连接数据库:ERROR: The server time zone value '�й�' is unrecognized or represents more than one time zone
- The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone
- Mysql错误:The server time zone value is unrecognized or represents more than one time zone
- The server timezone value 'UTC' is unrecognized or represents more than one timezone
- mysql连接异常:The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zo
- The server time zone value 'EDT' is unrecognized or represents more than one time zone.
- Err:The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array
- bug: The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone.
- 数据库连接 The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone.
- The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone.
- The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You m
- mysql出现错误:The server time zone value is unrecognized or represents more than one time zone
- The server time zone value '?й???????' is unrecognized or represents more than one time zone. You mu
- Mysql错误:The server time zone value is unrecognized or represents more than one time zone
- The server timezone value 'xxx' is unrecognized or represents more than one time