1. 随机数组
from numpy import *
random.rand(4,4)
输出
array([[ 0.81273873, 0.93985098, 0.72256469, 0.83294612],
[ 0.06087078, 0.85160009, 0.88331584, 0.8634025 ],
[ 0.328648 , 0.74410427, 0.07213059, 0.51864295],
[ 0.73424426, 0.75289487, 0.56867247, 0.61839992]])
2. 矩阵
矩阵和逆矩阵
randMat=mat(random.rand(4,4))
randMat.I
matrix([[ 0.33672204, 0.94254807, -1.46432126, 0.23631155],
[ 1.47878348, -1.01914042, 0.23114864, -0.05431002],
[-0.06186018, 0.38974979, 0.89236284, -0.45058119],
[-1.60231928, -0.44524619, 1.58433726, 1.1328065 ]])
3. 查找帮助信息
from numpy import *
help(zeros)
Help on built-in function zeros in module numpy.core.multiarray:
zeros(...)
zeros(shape, dtype=float, order='C')
Return a new array of given shape and type, filled with zeros.
Parameters
----------
shape : int or sequence of ints
Shape of the new array, e.g., ``(2, 3)`` or ``2``.
dtype : data-type, optional
The desired data-type for the array, e.g., `numpy.int8`. Default is
`numpy.float64`.
order : {'C', 'F'}, optional
Whether to store multidimensional data in C- or Fortran-contiguous
(row- or column-wise) order in memory.
4. 计算矩阵行数和列数
from numpy import *
import operator
a =mat([[1,2,3],[5,6,9]])
a
matrix([[1, 2, 3],
[5, 6, 9]])
shape(a)
(2, 3)
a.shape[0] #计算行数
2
a.shape[1] #计算列数
3