python - numpy.argwhere 文档中的“按元素分组”是什么意思?
问题描述
Numpy argwhere 文档说:
def argwhere(a):
"""
Find the indices of array elements that are non-zero, grouped by element.
...
然而实际的实现只是
return transpose(nonzero(a))
因此不执行重新排序或分组。
我希望
import numpy as np
x = np.full((2,3),6)
x[:,1] = 5
np.argwhere(x)
会回来
array([[0, 1],
[1, 1],
[0, 0],
[0, 2],
[1, 0],
[1, 2]])
相反,它返回
array([[0, 0],
[0, 1],
[0, 2],
[1, 0],
[1, 1],
[1, 2]])
我错过了什么还是文档中的错误?
解决方案
[0,1]
是数组的一个元素的索引。[1,1]
用于下一个非零元素。不要试图在那个措辞中阅读任何深刻的东西。它只是试图将它与返回的数组元组进行对比np.nonzero
。在nonzero
“分组”中是按维度。
推荐阅读
- python - 如何在 Python 中使用 Youtube API 在频道中创建广播?
- unix - 文本处理忽略下划线的第二次出现
- python - 如何在找到第一个所需字符并复制其余文本后停止搜索?
- c# - BenchmarkDotNet - 如何在类之外注入参数
- elixir - Access.get/3 中没有函数子句匹配 - 为什么会出现此错误?
- r - 不同大小的亚组内的随机化
- python - Python记录器异常文件
- c - 当我使用条件运算符或没有返回语句的 if 语句时,函数返回正确的值
- java - java中的模板方法模式
- java - 如何更改 TextView 的大小和颜色?