 # numpy.zeros() in Python

## numpy.zeros() in Python

The numpy.zeros() function returns a new array of given shape and type, with zeros.
Syntax:

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

Parameters :

```shape : integer or sequence of integers
order  : C_contiguous or F_contiguous
C-contiguous order in memory(last index varies the fastest)
C order means that operating row-rise on the array will be slightly quicker
FORTRAN-contiguous order in memory (first index varies the fastest).
F order means that column-wise operations will be faster.
dtype : [optional, float(byDeafult)] Data type of returned array.
```

Returns :

`ndarray of zeros having given shape, order and datatype.`

Code 1 :

 `# Python Program illustrating` `# numpy.zeros method` ` ` `import` `numpy as geek` ` ` `b ``=` `geek.zeros(``2``, dtype ``=` `int``)` `print``(``"Matrix b : \n"``, b)` ` ` `a ``=` `geek.zeros([``2``, ``2``], dtype ``=` `int``)` `print``(``"\nMatrix a : \n"``, a)` ` ` `c ``=` `geek.zeros([``3``, ``3``])` `print``(``"\nMatrix c : \n"``, c)`

Output :

```Matrix b :
[0 0]

Matrix a :
[[0 0]
[0 0]]

Matrix c :
[[ 0.  0.  0.]
[ 0.  0.  0.]
[ 0.  0.  0.]]
```

Code 2 : Manipulating data types

 `# Python Program illustrating` `# numpy.zeros method` ` ` `import` `numpy as geek` ` ` `# manipulation with data-types` `b ``=` `geek.zeros((``2``,), dtype``=``[(``'x'``, ``'float'``), (``'y'``, ``'int'``)])` `print``(b)`

Output :

```[(0.0, 0) (0.0, 0)]
```

Note : zeros, unlike zeros and empty, does not set the array values to zero or random values respectively.Also, these codes won’t run on online-ID. Please run them on your systems to explore the working.

Last Updated on October 29, 2021 by admin

## Python – math.cos() functionPython – math.cos() function

Python | math.cos() function In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.cos() function returns the cosine of value passed as argument. The value passed in this function should be in

## How to select rows from a dataframe based on column values ?How to select rows from a dataframe based on column values ?

How to select rows from a dataframe based on column values ? The rows of a dataframe can be selected based on conditions as we do use the SQL queries. The various methods to achieve this is explained in this

## numpy.subtract() in Pythonnumpy.subtract() in Python

numpy.subtract() in Python numpy.subtract() function is used when we want to compute the difference of two array.It returns the difference of arr1 and arr2, element-wise. Syntax : numpy.subtract(arr1, arr2, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True[, signature, extobj], ufunc ‘subtract’)

## Calculate the Euclidean distance using NumPyCalculate the Euclidean distance using NumPy

Calculate the Euclidean distance using NumPy In simple terms, Euclidean distance is the shortest between the 2 points irrespective of the dimensions. In this article to find the Euclidean distance, we will use the NumPy library. This library used for manipulating multidimensional

## numpy.mean() in Pythonnumpy.mean() in Python

numpy.mean() in Python numpy.mean(arr, axis = None) : Compute the arithmetic mean (average) of the given data (array elements) along the specified axis. Parameters : arr : [array_like]input array. axis : [int or tuples of int]axis along which we want to calculate the arithmetic

## How to create a vector in Python using NumPyHow to create a vector in Python using NumPy

How to create a vector in Python using NumPy NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Numpy is

## numpy.where() in Pythonnumpy.where() in Python

numpy.where() in Python The numpy.where() function returns the indices of elements in an input array where the given condition is satisfied. Syntax :numpy.where(condition[, x, y]) Parameters: condition : When True, yield x, otherwise yield y. x, y : Values from which to choose. x,

## numpy.argmax() in Pythonnumpy.argmax() in Python

numpy.argmax() in Python The numpy.argmax() function returns indices of the max element of the array in a particular axis. Syntax :  numpy.argmax(array, axis = None, out = None) Parameters :  array : Input array to work on axis : [int, optional]Along a