问题
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