NumPy: zeros() function
zeros() function
The zeros() function is used to get a new array of given shape and type, filled with zeros.
Syntax:
numpy.zeros(a, dtype=None, order='K', subok=True)
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
shape | Shape of the new array, e.g., (2, 3) or 2. | Required |
dtype | The desired data-type for the array, e.g., numpy.int8. Default is numpy.float64. | optional |
order | Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory | optional |
Return value:
[ndarray] Array of zeros with the given shape, dtype, and order.
Example: numpy.zeros() function
>>> import numpy as np
>>> a = (3,2)
>>> np.zeros(a)
array([[ 0., 0.],
[ 0., 0.],
[ 0., 0.]])
Pictorial Presentation:
Example: numpy.zeros() where data type is int
>>> import numpy as np
>>> np.zeros(6)
array([ 0., 0., 0., 0., 0., 0.])
>>> np.zeros((6,), dtype=int)
array([0, 0, 0, 0, 0, 0])
>>> np.zeros((3, 1))
array([[ 0.],
[ 0.],
[ 0.]])
Pictorial Presentation:
Python - NumPy Code Editor:
Previous: ones_like()
Next: zeros_like()
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework