Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
-inf負の数を与えるnumpy配列の対数のような関数を効率的に書く方法はありますか?
-inf
私が望む動作は次のとおりです。
>>> log_inf(exp(1)) 1.0 >>> log_inf(0) -inf >>> log_inf(-1) -inf
-inf負の数に対して返されます。
編集:現在、clip負の数を に置き換えるために使用して0いますが、機能しますが、効率的ですか?
clip
0
別の可能な解決策は次のとおりです。
np.nan_to_num(np.log(data), neginf=0)
または、多くの目的で、Numpy マスク配列を使用するとうまくいく場合があります。
np.ma.log(data)