×

numpy.zeros in Python

numpy.zeros in Python

The zeros() method of Python numpy class returns a new array of given shape and type, filled with zeros.

Syntax

numpy.zeros(shape, dtype=float, order='C')

Parameter

The numpy.zeros() method consists of three parameters, which are as follows:

shape : This parameter represents the shape of the new array.

order  : The order parameter can be either C_contiguous or F_contiguous. C order means that operating row-rise on the array will be slightly quicker

FORTRAN-contiguous order in memory (the first index varies the fastest). F order means that column-wise operations will be faster.

dtype : It is an optional parameter. It depicts the data type of returned array, and by default, it is a float.

Return

This method returns the array of zeros with the specified shape, order and datatype.

Example 1

# Python Programming giving an example for
# numpy.zeros() method
import numpy as numpy
obj1 = numpy.zeros(2, dtype = int)
print("Matrix : \n", obj1)
obj2 = numpy.zeros([2, 2], dtype = int)
print("\nMatrix : \n", obj2)  
obj3 = numpy.zeros([3, 3])
print("\nMatrix : \n", obj3)

Output

Original array :
[[0 1]
[2 3]
[4 5]
[6 7]
[8 9]]
Matrix :
[[ 1.  1.]
[ 1.  1.]
[ 1.  1.]
[ 1.  1.]
[ 1.  1.]]
Matrix :
[1 1 1 1 1 1 1 1]

Related Topics

numpy.diagflat() in Python

numpy.diagflat() in Python The diagflat() function of Python numpy class creates a two-dimensional array with the array_like input as a diagonal to the new output array. Syntax numpy.diagflat (a, k = 0) Parameter a :...

1 minute read.

numpy.tril() in Python

numpy.tril() in Python The tril() function of Python numpy class returns a copy of an array with the elements above the k-th diagonal zeroed. Syntax numpy.tril(m, k=0) Parameter a: It represents the input array k: This parameter represents...

1 minute read.

Read numpy array

Numpy is a numerical python that deals with multi-dimensional arrays mostly used in storing multiple values. Python's core scientific computing package is called NumPy. This Python library offers a multidimensional...

3 minutes read.

numpy.broadcast_arrays() in Python

numpy.broadcast_arrays() in Python The numpy.broadcast_arrays() function broadcasts any number of arrays against each other. Syntax numpy.broadcast_arrays(*args, **kwargs) Parameter  The numpy.broadcast_arrays() function has two parameters which are as follows: `*args`: This parameter represents the arrays to broadcast. subok: It is an optional parameter...

1 minute read.

numpy.ndarray.flatten() in Python

numpy.ndarray.flatten() in Python The numpy.ndarray.flatten() returns a copy of the array collapsed into 1-dimension. Syntax ndarray.flatten(order='C') Parameter The numpy. ndarray.flatten() method consists of one parameter, which is as follows: order : This parameter can be either...

1 minute read.

numpy.append() in Python

numpy.append() in Python The numpy.append() function appends the values to the end of an array. Syntax numpy.append(arr, values, axis=None) Parameter The numpy.append() function consists of three parameters, which are as follows: arr : This parameter represents the values that are...

1 minute read.

numpy.linspace() in Python

numpy.linspace() in Python The linspace() function of Python numpy class returns the number spaces equally over the given interval i.e.  [start, stop]. Syntax numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0) Parameter start: It is an optional parameter which represents the start of the...

1 minute read.

numpy.trim_zeros() in Python

numpy.trim_zeros() in Python The numpy.trim_zeros() trims the leading and/or trailing zeros from a 1-D array or sequence. Syntax numpy.trim_zeros(filt, trim='fb') Parameter The numpy.trim_zeros() function consists of two parameters, which are as follows: filt : This parameter represents the 1-D...

1 minute read.

numpy.column_stack() in Python

numpy.column_stack() in Python The numpy.column_stack() function stacks  the 1-D arrays as columns into a 2-D array. It takes a sequence of 1-D arrays and stacks them as columns to make a...

1 minute read.

numpy.empty_like() in Python

numpy.empty_like() in Python The empty_like() method of Python numpy class returns a new array with the same shape and type as the specified array. Syntax numpy.empty_like(prototype, dtype=None, order='K', subok=True) Parameters The numpy. empty_like() method consists of four parameters,...

1 minute read.

numpy.squeeze() in Python

numpy.squeeze() in Python The numpy.squeeze() function removes single-dimensional entries from the shape of an array. Syntax numpy.squeeze(a, axis=None) Parameter The numpy.squeeze() function has three parameters which are as follows: a: It represents the Input data. axis: This parameter signifies an int or...

1 minute read.

numpy.tri() in Python

numpy.tri() in Python The tri() function of Python numpy class returns an array with ones at and below the given diagonal(k value) and zeros elsewhere. Syntax numpy.tri(N, M=None, k=0, dtype=<class 'float'>) Parameter R : It represents the number...

1 minute read.

numpy.concatenate() in Python

numpy.concatenate() in Python The numpy.concatenate() function joins a sequence of arrays along an existing axis. Syntax numpy.concatenate((a1, a2, ...), axis=0, out=None) Parameter a1, a2, … : This parameter represents the sequence of the array where they must have the same shape,...

1 minute read.

numpy.asarray_chkfinite() in Python

numpy.asarray_chkfinite() in Python The numpy.asarray_chkfinite() function converts the input to an array, checking for NaNs or Infs. Syntax numpy.asarray_chkfinite(a, dtype=None, order=None) Parameter a : This parameter represents an input data, which can be in the form of lists, tuples,...

2 minutes read.

numpy.swapaxes() in Python

numpy.swapaxes() in Python The numpy.swapaxes() function interchanges the two specified axes of the given array. Syntax numpy.swapaxes(a, axis1, axis2) Parameter The numpy.swapaxes() method consists of three parameters, which are as follows: a : This parameter represents the Input array. axis1 : It represents...

1 minute read.

numpy.delete() in Python

numpy.delete() in Python The numpy.delete() function returns a new array with sub-arrays along an axis deleted. For 1-D array, this function returns those entries which are not returned by arr[obj]. Syntax numpy.delete(arr, obj, axis=None) Parameter arr: This parameter returns...

2 minutes read.

numpy.diag() in Python

numpy.diag() in Python The diag() function of Python numpy class extracts and construct a diagonal array. Syntax numpy.diag(v, k=0) Parameter a: It represents the array_like. k: It represents the diagonal value that we require. It is an...

1 minute read.

numpy.identity() in Python

numpy.identity() in Python The identity() method of Python numpy class returns an identity matrix i.e., a square matrix with ones on the main diagonal. Syntax numpy.identity(n, dtype=None) Parameters The numpy. identity()  method consists of two parameters,...

1 minute read.

numpy.atleast_2d() in Python

numpy.atleast_2d() in Python The numpy.atleast_2d() function converts the inputs as arrays with at least two dimensions. Syntax numpy.atleast_2d(*arys) Parameter arys1, arys2, … : This parameter represents one or more array-like sequences where the non-array inputs are converted...

1 minute read.

Python NumPy Tutorial

NumPy is a scientific library in Python Programming Language. It provides objects and routines for fast operations on arrays, random simulations, statistical operations, sorting, etc. Numpy has an ndarray object which...

2 minutes read.