整理索引以访问元素? [英] flatten out indices in order to access elements?

查看:79
本文介绍了整理索引以访问元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有:

one = np.array([ [2,3,np.array([ [1,2],  [7,3]   ])],
                 [4,5,np.array([ [11,12],[14,15] ])]
               ], dtype=object)


two = np.array([ [1,2] ,[7, 3],
                 [11,12] , [14,15] ])

我希望能够将one数组中的值与two数组中的值进行比较.

I want to be able to compare the values that are in the array of the one array, with the values of two array.

我在说

[1,2] ,[7, 3],
[11,12] , [14,15]

所以,我想一一检查它们是否相同.

So, I want to check if they are the same, one by one.

大概像:

for idx,x in np.ndenumerate(one):
    for idy,y in np.ndenumerate(two):
        print(y)

给出two的所有元素.

我无法弄清楚如何同时访问one的所有元素(但仅是每行的最后一个元素)并将它们与two

I can't figure how to access at the same time all elements (but only the last from each row) of one and compare them with two

问题在于它们的尺寸不相同.

The problem is that they don't have the same dimensions.

推荐答案

有效

np.r_[tuple(one[:, 2])] == two

输出:

array([[ True,  True],
       [ True,  True],
       [ True,  True],
       [ True,  True]], dtype=bool)

这篇关于整理索引以访问元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆