BetterDocs
Home
Docs

Creation | np.zeros()

Method:

np.zeros(shape, dtype=np.float64, order='C', *, like=None)

Creates a NumPy array of the entered shape filled with zeros.

Returns:

np.ndarray

Parameters:

shape: (list, tuple)-

Specifies the dimensions of the array to be filled with zeros.

import numpy as np
# (row, col) or [row, col] to be fed as shape
zeros_array = np.zeros(shape=[2, 3])
print(zeros_array)
'''
Output:
[[0. 0. 0.]
 [0. 0. 0.]]
'''

dtype: np.float64, Optional-

The desired data-type for the array.

import numpy as np
# (row, col) or [row, col] to be fed as shape
zeros_array = np.zeros(shape=[2, 3], dtype=np.int8)
print(zeros_array.dtype) # int8

Values: +

By passing the dtype, you are implicitly converting the values to the passed dtype.

order: {'C', 'F'}, Optional-

Specifies the memory layout order for multi-dimensional arrays.

order = C (default) +

order = F +

Refer to np.array()  for better explanation & examples for order.

.ravel()  is a NumPy function used to flatten a multi-dimensional array into a 1D array.

like: None, Optional-

The like parameter in np.zeros() was introduced to make array creation more flexible, particularly for compatibility with libraries that extend NumPy, like Dask, CuPy, or other libraries that create arrays compatible with np.ndarray but optimized for different backends (e.g., parallel processing or GPU-based arrays).


Logo

BetterDocs

Support

EmailDiscordForms

Documentations

Python

Company

AboutDocs

Policies

Terms of ServicePrivacy Policy