Detect if a NumPy array contains at least one non-numeric value?

后端 未结 5 1406
逝去的感伤
逝去的感伤 2021-01-30 07:46

I need to write a function which will detect if the input contains at least one value which is non-numeric. If a non-numeric value is found I will raise an error (because the ca

5条回答
  •  时光说笑
    2021-01-30 08:29

    With numpy 1.3 or svn you can do this

    In [1]: a = arange(10000.).reshape(100,100)
    
    In [3]: isnan(a.max())
    Out[3]: False
    
    In [4]: a[50,50] = nan
    
    In [5]: isnan(a.max())
    Out[5]: True
    
    In [6]: timeit isnan(a.max())
    10000 loops, best of 3: 66.3 µs per loop
    

    The treatment of nans in comparisons was not consistent in earlier versions.

提交回复
热议问题