×

numpy.zeros_like() in Python

Numpy.zeros_like() in Python The zeros_like() method of Python numpy class returna an array of zeros with the same shape and type as that of specified array. Syntax
numpy.zeros_like(a, dtype=None, order='K', subok=True)
Parameter The numpy.zeros_like() method consists of four parameters, which are as follows: arrray : This parameter represents an array_like input subok  :It true is invoked then it represents  newly created array will be sub-class of array else it represents  a base-class 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 an array of zeros having given shape, order and datatype. Example 1
# Python Programming giving an example for
# numpy.zeros_like method
importnumpy as numpy
array = numpy.arange(8).reshape(4, 2)
print("Original array : \n", array)
obj1 = numpy.zeros_like(array, float)
print("\nMatrix : \n", obj1)
array = numpy.arange(7)
obj2 = numpy.zeros_like(array)
print("\nMatrix : \n", obj1)
Output Original array :
[[0 1]
 [2 3]
 [4 5]
[6 7]]
Matrix :
 [[ 0.  0.]
[ 0.  0.]
[ 0.  0.]
[ 0.  0.]]
Matrix :
[[ 0.  0.]
[ 0.  0.]
[ 0.  0.]
[ 0.  0.]]

Related Topics

Numpy Attributes

Numpy Attributes The Numpy collections give attributes to the numpy arrays. These attributes assist us with knowing the shape, aspect, and different properties of a given numpy array. As we know,...

4 minutes 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.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.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.

numpy.logspace() in Python

numpy.logspace() in Python The logspace() function of Python numpy class returns the equal number of spaces over every interval on a log scale. Syntax numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0) Parameter start: It represents the start of the interval range. stop:...

1 minute read.

numpy.eye() in Python

numpy.eye() in Python: The eye() method of Python numpy class returns a 2-D array with ones on the diagonal and zeros elsewhere. Syntax numpy.eye(N, M=None, k=0, dtype=<class 'float'>, order='C') Parameters The numpy.eye()  method consists of five parameters, which...

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.copyto() in Python

numpy.copyto() in Python The numpy.copyto() function copies values from one array to another array. Syntax numpy.copyto(dst, src, casting='same_kind', where=True) Parameter The numpy. copyto() method consists of three parameters, which are as follows: dst : It represents the array into which our...

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.asmatrix() in Python with Example

Numpy.asmatrix() in Python The asmatrix() function returns the specified input as a matrix. It does not make a copy if the input is already a matrix or an ndarray. Syntax numpy.asmatrix(data, dtype=None) Parameter data  :This parameter...

1 minute read.

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.ones() in Python

numpy.ones() in Python The ones() method of Python numpy class returns a new array of given shape and type, filled with ones. Syntax numpy.ones(shape, dtype=None, order='C') Parameter The numpy.ones() method consists of three parameters, which are as...

1 minute read.

numpy.frombuffer() in Python

numpy.frombuffer() in Python The frombuffer()  function of Python numpy class creates an array by using the given buffer. Syntax numpy.frombuffer(buffer, dtype=float, count=-1, offset=0) Parameter The numpy.frombuffer() method consists of four parameters, which are as follows: buffer: This parameter...

1 minute read.

numpy.atleast_3d() in Python

numpy.atleast_3d() in Python The numpy.atleast_3d() function views the inputs as arrays with at least three dimensions. Syntax numpy.atleast_3d(*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.

numpy.empty() in Python

numpy.empty() in Python The empty() method of Python numpy class returns a new array of the specified shape and type, without initializing the entries. Syntax numpy.empty(shape, dtype=float, order='C') Parameters The numpy.empty method consists of three parameters, which...

1 minute read.

Numpy.copy() in Python with Example

Numpy.copy() in Python The copy() function of Python numpy class returns an array copy for the given object. Syntax numpy.copy(a, order='K') Parameter a: It represent the array_like input data. order :  This parameter controls the memory layout of...

1 minute read.

numpy.fromstring () in Python

numpy.fromstring () in Python The fromstring() function of Python numpy class creates a new 1-D array initialized from raw binary or text data in a string. Syntax numpy.fromstring(string, dtype=float, count=-1, sep='') Parameter The numpy.fromstring() method...

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.ones_like() in Python

numpy.ones_like() in Python The one_like() method of Python numpy class returns an array of ones with the same shape and type as the specified array. Syntax numpy.ones_like(a, dtype=None, order='K', subok=True) Parameter The numpy.ones_like() method consists of four parameters,...

1 minute read.