Functions to construct arrays
The usual way to set up an array is via a list. But there are also a couple of convenient methods for generating special arrays, which are given in the following table (Table 4.5):
|
Methods |
Shape |
Generates |
|
|
(n,m) |
Matrix filled with zeros |
|
|
(n,m) |
Matrix filled with ones |
|
|
(n,n) |
(Sub-, super-) diagonal matrix from a vector v |
|
|
(n,m) |
Matrix filled with uniformly distributed random numbers in (0,1) |
|
|
(n,) |
First n integers |
|
|
(n,) |
Vector with n equispaced points between a and b |
Table 4.5: Commands to create arrays
These commands may take additional arguments. In particular, the commands zeros, ones, and arange take dtype as an optional argument. The default type is float, except for arange. There are also methods such as zeros_like and ones_like, which are slight variants of the preceding ones. For instance, the zeros_like(A) method is equivalent...