裏 RjpWiki

Julia ときどき R, Python によるコンピュータプログラム,コンピュータ・サイエンス,統計学

Python の変な仕様?(その2)

2020年12月03日 | Python

>>> import numpy as np
>>> x = sp.array([1,3,7])
>>> x -= 0.3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'subtract' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

>>> x = x-0.3

としてやれば文句は言わない

あるいは,float にしてやれば文句は言わない

>>> x = np.array([1,3,7], dtype=float)
>>> x -= 0.3

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

PVアクセスランキング にほんブログ村

PVアクセスランキング にほんブログ村