当我尝试将“uint16”字段加入 NumPy 1.11 或 1.12(Python 3.5)中的结构化数组时遇到 TypeError。
import numpy as np
from numpy.lib import recfunctions as rfn
foo = np.array([(1,)],
dtype=[('key', int)])
bar = np.array([(1,np.array([1,2,3]))],
dtype=[('key', int), ('value', 'uint16', 3)])
rfn.join_by('key', foo, bar)
这是错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/anaconda3/lib/python3.5/site-packages/numpy/lib/recfunctions.py", line 986, in join_by
output.sort(order=key)
File "/home/user/anaconda3/lib/python3.5/site-packages/numpy/ma/core.py", line 5420, in sort
sidx = self.filled(filler).argsort(axis=axis, kind=kind,
File "/home/user/anaconda3/lib/python3.5/site-packages/numpy/ma/core.py", line 3668, in filled
fill_value = _check_fill_value(fill_value, self.dtype)
File "/home/user/anaconda3/lib/python3.5/site-packages/numpy/ma/core.py", line 470, in _check_fill_value
fill_value = np.array(_recursive_set_fill_value(fill_value, ndtype),
File "/home/user/anaconda3/lib/python3.5/site-packages/numpy/ma/core.py", line 436, in _recursive_set_fill_value
output_value.append(np.array(fval, dtype=cdtype).item())
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
如果我使用“float16”,则不会出现同样的问题。
import numpy as np
from numpy.lib import recfunctions as rfn
foo = np.array([(1,)],
dtype=[('key', int)])
bar = np.array([(1,np.array([1,2,3]))],
dtype=[('key', int), ('value', 'float16', 3)])
rfn.join_by('key', foo, bar)
这只是一个错误吗?或者有什么方法可以防止这个问题?