ndarray python 映射_找到一组索引,将一个NumPy ndarray的行映射到另一个

因为两个数组中的任何一个都可以被洗牌以匹配另一个,所以没有人阻止我们重新排列这两个数组。使用Jaime's Answer,我们可以vstack两个数组并找到唯一的行。unique返回的反向索引本质上就是所需的映射(因为数组不包含重复的行)。在

为了方便起见,我们先定义一个unique2d函数:def unique2d(arr,consider_sort=False,return_index=False,return_inverse=False):

"""Get unique values along an axis for 2D arrays.

input:

arr:

2D array

consider_sort:

Does permutation of the values within the axis matter?

Two rows can contain the same values but with

different arrangements. If consider_sort

is True then those rows would be considered equal

return_index:

Similar to numpy unique

return_inverse:

Similar to numpy unique

returns:

2D array of unique rows

If return_index is True also returns indices

If return_inverse is True also returns the inverse array

"""

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值