簡體   English   中英

用0替換inf值的列

[英]Replacing column of inf values with 0

我是numpy的新手,但我似乎無法讓這段代碼工作。

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

item3是numpy數組的向量,每個數組中有300個維度。

拋出的錯誤是無效的語法。 我如何實現這個功能。

但是,鑒於它是float64 numpy向量的向量。 數據類型是object。 它會引發異常

TypeError: ufunc 'isinf' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Item3是包含每個具有300維度的元素的列

你可以做出類似的東西:

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

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM