'&' and 'and' difference in python

idx_b = data[:,1] == 0 and data[:,4] == 1

用and会提示错误, 因为and 最终只给定一个bool值, 要么用.all() 或 .any()

所以这里用& 是正确, 会给定一个bool值的array, 它是elementwise的

https://stackoverflow.com/questions/10062954/valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambiguous

发布了755 篇原创文章 · 获赞 195 · 访问量 104万+

猜你喜欢

转载自blog.csdn.net/seamanj/article/details/104957198