weider - 8 months ago 56

Python Question

How to supplemented by an numpy array of zeros?

`arr=np.array([1,10])`

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

`arr+[0]*(size-len)`

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])
```