【发布时间】:2020-08-31 23:06:14
【问题描述】:
我注意到numpy.full() 中的fill_value 参数可以是一个数组。
>>> a = np.arange(5)
>>> a
array([0, 1, 2, 3, 4])
>>> b = np.full( (5,10), a[:,None], dtype=np.int16 )
>>> b
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
[3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4]], dtype=int16)
但是,我注意到 CuPy 中的 fill_value 参数不能。
>>> b_gpu = cp.full( (5,10), a[:,None], dtype=np.int16 )
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
b_gpu = cp.full( (5,10), a[:,None], dtype=np.int16 )
File "/home/master/.local/lib/python3.6/site-packages/cupy/creation/basic.py", line 271, in full
a.fill(fill_value)
File "cupy/core/core.pyx", line 499, in cupy.core.core.ndarray.fill
File "cupy/core/core.pyx", line 510, in cupy.core.core.ndarray.fill
ValueError: non-scalar numpy.ndarray cannot be used for fill
是否缺少功能或我编写 CuPy 的方式有错误?
【问题讨论】: