What is going on behind this numpy selection behavior?

强颜欢笑 提交于 2019-11-29 14:06:21

nptest is a 2D array of object dtype, and the first element of each row is a list.

nptest[:, 0] is a 1D array of object dtype, each of whose elements are lists.

When you do nptest[:,0]==[1], NumPy does not perform an elementwise comparison of each element of nptest[:,0] against the list [1]. It creates as high-dimensional an array as it can from [1], producing the 1D array np.array([1]), and then broadcasts the comparison, comparing each element of nptest[:,0] against the integer 1.

Since no list in nptest[:, 0] is equal to 1, all elements of the result are False.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!