LoginSignup
1
0

More than 5 years have passed since last update.

Numpy > Error > TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' > 対処

Last updated at Posted at 2017-10-28
動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.2.1
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
scipy v0.19.1
geopandas v0.3.0

関連

link > Python で 1 変量データ補間 > SciPy > interpolate.*
ADDA + Matplotlib > InitField-Y for various values of Re{m}

エラー

ADDAの計算結果を補間しようとしたらエラーになった。

再現コードは以下。

test_interpolate_171028.py
import numpy as np
import sys
from scipy import signal, interpolate

# on Python 3.5.2

xs = ['1.33', '1.41', '1.25', '1.69', '1.05', '1.85', '1.17', '1.37', '1.49', '1.65', '1.77', '1.53', '1.09', '1.81', '1.13', '1.61', '1.57', '1.29', '1.73', '1.21', '1.45']
ys = [-0.026233794340000002, -0.022115366130000001, -0.023346986680000001, 0.0098408259539999998, -0.0039200259860000001, 0.045906058600000001, -0.016363607209999999, -0.025000819000000001, -0.015049274919999999, 0.0016250158680000001, 0.031175279090000001, -0.01194725152, -0.0078601925140000008, 0.041183378409999999, -0.01215601187, -0.0044200969, -0.0086785273040000006, -0.02554396125, 0.019991008380000001, -0.020176115410000001, -0.018504119140000001]

print(xs, ys)

xns = np.array(xs)
yns = np.array(ys)

tt = np.linspace(1.1, 1.8, 51)
print(tt)

f3 = interpolate.interp1d(xns, yns, kind="cubic")
y3 = f3(tt)
run
Traceback (most recent call last):
  File "test_interpolate_171028.py", line 18, in <module>
    f3 = interpolate.interp1d(xns, yns, kind="cubic")
  File "/usr/local/lib/python3.5/dist-packages/scipy/interpolate/interpolate.py", line 488, in __init__
    if np.isnan(self.x).any():
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

対処

参考: https://stackoverflow.com/questions/40809503/python-numpy-typeerror-ufunc-isfinite-not-supported-for-the-input-types

xns = np.array(xs)

を以下にすることでエラーを回避できる。

xns = np.array(xs, dtype=float)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0