本文通过对以下题目进行分析与解答,从而了解Numpy的用法。
其中第一节为基本知识介绍,第二节为题目解答。
题目如下:
基础知识:
1.numpy中的axis
axis常常出现在numpy对矩阵的操作中,指定不同的axis可以从不同方向(如二维矩阵中,axis=0沿纵向,axis=1沿横向)进行操作。
以下是解题过程中所需用到的函数:
1. numpy.random.normal(分别以loc和scale为均值与标准差,随机生成size个数)
numpy.random.
normal
(loc=0.0, scale=1.0, size=None)
Draw random samples from a normal (Gaussian) distribution.
The probability density function of the normal distribution, first derived by De Moivre and 200 years later by both Gauss and Laplace independently [R500500], is often called the bell curve because of its characteristic shape (see the example below).
The normal distributions occurs often in nature. For example, it describes the commonly occurring distribution of samples influenced by a large number of tiny, random disturbances, each with its own unique distribution [R500500].
Parameters: | loc : float or array_like of floats
scale : float or array_like of floats
size : int or tuple of ints, optional
|
---|---|
Returns: | out : ndarray or scalar
|
2. scipy.linalg.toeplitz(生成一个第一行向量为c,第一列向量为r的托普利兹矩阵)
-
scipy.linalg.
toeplitz
(
c,
r=None
)
-
Construct a Toeplitz matrix.
The Toeplitz matrix has constant diagonals, with c as its first column and r as its first row. If r is not given, r ==conjugate(c) is assumed.
Parameters: c : array_like
First column of the matrix. Whatever the actual shape of c, it will be converted to a 1-D array.
r : array_like
First row of the matrix. If None, r = conjugate(c) is assumed; in this case, if c[0] is real, the result is a Hermitian matrix. r[0] is ignored; the first row of the returned matrix is [c[0], r[1:]]. Whatever the actual shape of r, it will be converted to a 1-D array.
Returns: A : (len(c), len(r)) ndarray
The Toeplitz matrix. Dtype is the same as (c[0] + r[0]).dtype.
3. numpy.dot(如果a,b为一维矩阵,则计算二者的内积;若a,b为二维数组,则进行二者的矩阵乘法运算)
numpy.
dot
(
a,
b,
out=None</