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 Table 4.5:
Methods |
Shape |
Generates |
zeros((n,m)) |
(n,m) |
Matrix filled with zeros |
ones((n,m)) |
(n,m) |
Matrix filled with ones |
full((n,m),q) |
(n,m) |
Matrix filled with |
diag(v,k) |
(n,n) |
(Sub-, super-) diagonal matrix from a vector |
random.rand(n,m) |
(n,m) |
Matrix filled with uniformly distributed random numbers in (0,1) |
arange(n) |
(n,) |
First integers |
linspace(a,b,n) |
(n,) |
Vector with equispaced points between and |
Table 4.5: Commands to create arrays
These commands may take additional arguments. In particular, the commands zeros, ones, full, and arange take dtype as an optional argument. The default type is float, except for arange. There are also methods...