【ディープラーニング】[numpy]DeprecationWarning: `np.int` | 夕湖津のブログ

夕湖津のブログ

問題解決に役立つ情報の提供を目指します

テーマ:

■前置き

オライリー・ジャパンの「ゼロから作る Deep Learning」14刷のP.47

 

■事象

3.2.3 ステップ関数のグラフのコードを動かした時に下記アラート

 

step.py:5: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  return np.array(x > 0, dtype=np.int)

 

■原因

Numpyの1.20では、numpy.intは非推奨になったため

 

実際、使用しているNumpyのバージョンを確認したところ、1.20.1でした。

 

>>> import numpy as np
>>> print(np.__version__)
1.20.1

↓Numpyのユーザガイドご参照

 

 

■解決方法

<Before>

return np.array(x > 0, dtype=np.int)

 

<After>

return np.array(x > 0, dtype=np.int64)