numba vstack doesn't work on list of arrays

半腔热情 提交于 2021-01-29 05:20:28

问题


It's weird for me vstack doesn't work with Numba when input is a list of array, it only works when the input is a tuple of array. Example code:

@nb.jit(nopython=True)
def stack(items):
    return np.vstack(items)

stack((np.array([1,2,3]), np.array([4,5,6])))

returns

array([[1, 2, 3],
       [4, 5, 6]])

but

stack([np.array([1,2,3]), np.array([4,5,6])])

Throws an error

TypingError: No implementation of function Function(<function vstack at 0x0000027271963488>) found for signature:
>>>vstack(reflected list(array(int32, 1d, C)))

Since tuple is not supported, I struggled to find a workaround - did I miss something?


回答1:


This is a workaround as @hpaulj mentioned:

stack(tuple([np.array([1,2,3]), np.array([4,5,6])]))

[[1 2 3]
 [4 5 6]]


来源:https://stackoverflow.com/questions/62680256/numba-vstack-doesnt-work-on-list-of-arrays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!