3

numpy.double が要素ごとにネストされたリスト要素に適用され、numpy.complex が適用されないのはなぜですか?

例を次に示します。

>>> import numpy
>>> L = [['1','2'],['2','3']]
>>> print numpy.double( L )
[[ 1.  2.]
 [ 2.  3.]]
>>> print numpy.complex( L )
Traceback (most recent call last):
  File "avr_std.py", line 17, in <module>
    print np.complex( L )
TypeError: complex() argument must be a string or a number
4

1 に答える 1

3

np.floatそしてnp.complex、通常のベクトル化されていない Python バージョンです。

>>> np.float is float
True
>>> np.complex is complex
True

numpy非スカラー入力を処理できるのは、固有のものです。

>>> np.float_([1,2])
array([ 1.,  2.])
>>> np.double is np.float_
True
>>> np.complex_([1,2])
array([ 1.+0.j,  2.+0.j])
>>> np.float32([1,2])
array([ 1.,  2.], dtype=float32)
>>> np.complex192([1,2])
array([ 1.0+0.0j,  2.0+0.0j], dtype=complex192)

等々。

于 2013-11-09T02:35:39.780 に答える