weider weider - 1 year ago 107
Python Question

supplement numpy array in python 3

How to supplemented by an numpy array of zeros?


if len(arr)<size:
*supplemented array of zeros to the size*.

For example sie =5;

if array = [1,2,3].
output array = [1,2,3,0,0].

Should I use fill or make new array like
Which way is faster?

Many thanks

Answer Source

I'd use ndarray.resize:

>>> a = np.array([1,2,3])
>>> a.resize((5,))
>>> a
array([1, 2, 3, 0, 0])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download