Monday, 15 September 2014

python - Efficient way for appending numpy array -



python - Efficient way for appending numpy array -

i maintain simple.i have loop appends new row numpy array...what efficient way this.

n=np.zeros([1,2]) x in [[2,3],[4,5],[7,6]] n=np.append(n,x,axis=1)

now thing there [0,0] sticking have remove

del n[0]

which seems dumb...so please tell me efficient way this.

n=np.empty([1,2])

is worse creates uninitialised value.

there 3 ways this, if have in list:

data = [[2, 3], [4, 5], [7, 6]] n = np.array(data)

if know how big final array be:

exp = np.array([2, 3]) n = np.empty((3, 2)) in range(3): n[i, :] = ** exp

if don't know how big final array be:

exp = np.array([2, 3]) n = [] = np.random.random() while < .9: n.append(i ** exp) = np.random.random() n = np.array(n)

just or record can start n = np.empty((0, 2)) not suggest appending array in loop.

python arrays numpy

No comments:

Post a Comment