saving . . . saved Doubt on the syntax of zeros method has been deleted. Doubt on the syntax of zeros method has been hidden .
Doubt on the syntax of zeros method
Title
Question
Mam why do we have to use 2 brackets in the zeros method for giving only 1 set of values to it? I have tried it with one braces(opening and closing) then it is giving error. My OS used : Windows 10 ==>
TypeError                                 Traceback (most recent call last)
<ipython-input-3-4b18b0e09899> in <module>
----> 1 b=np.zeros(2,2)

TypeError: data type not understood



Python-3.4.3 Getting-started-with-arrays 07-08 min 10-20 sec 28-04-20, 3:49 p.m. KnowsOnlyJava

Answers:

np.zeros accepts the shape of the array i.e. the number of rows and columns of the array as an argument. So it should be either a tuple or an integer value.
For example:
Executing np.zeros((2, 3)) gives 
array([[0., 0., 0.],
       [0., 0., 0.]])
which is a 2x3 array.

Executing np.zeros(2) gives
array([0., 0.])
which is a 1x2 array.

28-04-20, 3:58 p.m. aditya94palaparthy@gmail.com
Can you please explain the meaning of a tuple? Is it similar to concept of object of java?
28-04-20, 4:06 p.m. KnowsOnlyJava

Login to add comment


A tuple is one of the data structures in python. The tuples<span style="font-family: arial, sans-serif; font-size: 14px;"> are sequences, just like lists or arrays.</span>
 You will learn more about tuple in the Sequence datatypes tutorial.
28-04-20, 4:15 p.m. aditya94palaparthy@gmail.com
ok thank you very much
28-04-20, 4:27 p.m. KnowsOnlyJava

Login to add comment


Log-in to answer to this question.