同じフィールド名と型を異なる方法で使用して構造体配列を初期化すると、次のようになります。
>>> a = np.zeros(2, dtype=[('x','int64'),('y','a')])
>>> a
array([(0L, ''), (0L, '')],
dtype=[('x', '<i8'), ('y', 'S')])
したがって、タプルのリストを使用した初期化は正常に機能します。
>>> mdtype = dict(names=['x','y'],formats=['int64','a'])
>>> mdtype
{'names': ['x', 'y'], 'formats': ['int64', 'a']}
>>> a = np.zeros(2,dtype=mdtype)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: data type not understood
したがって、辞書で初期化することはできません。問題は文字列型です。
>>> mdtype = dict(names=['x','y'],formats=['int64','float64'])
>>> a = np.zeros(2,dtype=mdtype)
>>>
問題ありません。何か案は?これは Numpy のバグですか?
でこぼこのバージョン: 1.8.0
Python 2.7.6 (デフォルト、2013 年 11 月 10 日 19:24:24) [MSC v.1500 64 ビット (AMD64)] (win32)