Currently, I have some code like this
import numpy as np
ret = np.array([])
for i in range(100000):
tmp = get_input(i)
ret = np.append(ret, np.zeros(len(tmp)))
ret = np.append(ret, np.ones(fixed_length))
I think this code is not efficient as np.append
needs to return a copy of the array instead of modify the ret in-place
I was wondering whether I can use the extend
for a numpy array like this:
import numpy as np
from somewhere import np_extend
ret = np.array([])
for i in range(100000):
tmp = get_input(i)
np_extend(ret, np.zeros(len(tmp)))
np_extend(ret, np.ones(fixed_length))
So that the extend
would be much more efficient.
Does anyone have ideas about this?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…