If we need to initialize a numpy array with the same value then we use numpy.ndarray.fill (). Suppose we have to create a NumPy array of of length n, each element of which is v. Then we use this function a.fill (v). We don`t need to use loops to initialize the array if we use this fill ()
function.
Syntax : ndarray.fill (value)
Parameters:
value: All elements of a will be assigned this value.
Code # 1:

Output:
a is: [[1. 1. 1.] [1. 1. 1.] [1. 1. 1.]] After using fill () a is: [[1. 1. 1.] [1. 1. 1.] [1. 1. 1.]]
Code # 2:

Exit:
a is [0 1 2 3 4] Now a is : [0 0 0 0 0]
Code # 3: numpy.ndarray.fill () also works with multidimensional arrays.
# Python program explaining
# numpy.ndarray.fill () function
import
numpy as geek
a
=
geek.empty ([
3
,
3
])
# Using the fill () method
a.fill (
0
)
print
(
"a is:"
, a)
Exit :
a is: [[0. 0. 0.] [0. 0. 0.] [0. 0. 0.]]
We live in an age of socalled Big Data. We hear terms like data scientist, and there is much talk about analytics and the mining of large amounts of corporate data for tidbits of business value. Ther...
10/07/2020
Why this Book? Hadoop has been the base for most of the emerging technologies in today’s big data world. It changed the face of distributed processing by using commodity hardware for large data set...
10/07/2020
IRMA is a researchbased professional organization dedicated to advancing the concepts and practices of information resource management in modern organizations. The primary purpose of IRMA is to promo...
28/08/2021
During 2014, 2015, and 2016, surveys show that among all software developers, those with higher wages are the data engineers, the data scientists, and the data architects. This is because there is ...
10/07/2020