# python-scipyHow do I create an array of zeros with the same shape as an existing array using Python and NumPy?

Creating an array of zeros with the same shape as an existing array using Python and NumPy is easy. To do this, you can use the `np.zeros_like`

function. This function takes an existing array and creates a new array filled with zeros that has the same shape as the existing array.

For example:

```
import numpy as np
arr = np.array([[1,2,3],
[4,5,6]])
arr_zeros = np.zeros_like(arr)
print(arr_zeros)
```

## Output example

```
[[0 0 0]
[0 0 0]]
```

The code above creates an array `arr`

with shape `(2,3)`

and then creates a new array `arr_zeros`

with the same shape as `arr`

filled with zeros.

## Code explanation

`import numpy as np`

: Imports the NumPy library as`np`

.`arr = np.array([[1,2,3], [4,5,6]])`

: Creates an array`arr`

with shape`(2,3)`

.`arr_zeros = np.zeros_like(arr)`

: Creates a new array`arr_zeros`

with the same shape as`arr`

filled with zeros.`print(arr_zeros)`

: Prints the new array.

## Helpful links

### More of Python Scipy

- How can I use the Radial Basis Function (RBF) in Python with SciPy?
- How do I create a 2D array of zeros using Python and NumPy?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How do I create a numpy array of zeros using Python?
- How can I use Python and Numpy to parse XML data?
- How do I create a zero matrix using Python and Numpy?
- How do I create a numpy array of zeros using Python?
- How can I use Python and Numpy to zip files?
- How can I use Python and SciPy to find the zeros of a function?

See more codes...