December 2017
Intermediate to advanced
386 pages
10h 42m
English
Let's see how to do it all with a single value.
An alternative to empty() is the zeros() function, which creates an array where all elements are initialized to zero, as in the following example:
x = np.zeros((2,3))
The (2,3) tuple argument states that we want a 2 x 3 array of zeros, so we get the following result:
array([[ 0., 0., 0.], [ 0., 0., 0.]])
Notice that, by default, the data type of the array is float64. If an alternate data type is desired, it must be specified in the call to zeros(), as indicated in the following code:
x = np.zeros((2,3), dtype=np.int64)
This will create a 2 x 3 array of integers.
The ones() function creates an array where all elements are initialized to one, ...
Read now
Unlock full access