【发布时间】:2020-05-19 02:50:17
【问题描述】:
我想从一个数组B 中删除与另一个数组A 中的inf 元素具有相同索引的元素。
我有两个 numpy 数组,例如
A = np.array([1,2,3,4, float('inf')])
B = np.array([5, 6, 7, 8, 9])
如果我执行B[A>2],则输出为array([7, 8, 9])。但是,如果我执行B[math.isfinite(A)],则会出现错误
TypeError: only size-1 arrays can be converted to Python scalars
如何从B 中选择A 中的值不是无穷大的元素?
【问题讨论】:
-
this 回答你的问题了吗?
-
我使用的是 numpy 数组,而不是 pandas 数据帧。方法不太一样
-
另外,我的问题不是关于从
A中删除infs,而是关于从@987654336 中删除与infs 相同位置的元素到B@. -
math.Isfinite()不能将数组用作参数