将inf值列替换为0

2024-10-04 11:26:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新来的纽比,但我似乎不能让这段代码工作。在

item3.apply(lambda x : (x[np.isneginf(x)] = 0))

item3是一个numpy数组的向量,每个数组中有300个维度。在

引发的错误是无效语法。如何实现这个功能。在

但是,假设它是一个float64 numpy向量的向量。数据类型为object。它引发了一个例外

^{pr2}$

Item3是一个列,其中包含每个元素的维度为300


Tags: lambda代码功能numpyobject错误np语法
1条回答
网友
1楼 · 发布于 2024-10-04 11:26:35

你可以做这样的东西:

import numpy as np
from numpy import inf

x = np.array([inf, inf, 0]) # Create array with inf values

print x # Show x array

x[x == inf] = 0 # Replace inf by 0

print x # Show the result

{a1}

相关问题 更多 >