Numpy学习与应用(一)

本文通过解题介绍Numpy的基本知识,包括numpy.random.normal生成正态分布数据,scipy.linalg.toeplitz创建托普利兹矩阵,numpy.dot进行内积与矩阵乘法,numpy.eye生成单位矩阵,numpy.ones生成全1矩阵,numpy.linalg.solve求解线性方程,numpy.linalg.norm计算矩阵范数,numpy.random.standard_normal生成标准正态分布数据,numpy.zeros创建全0矩阵,numpy.random.binomial生成二项分布数据,numpy.argmax和argmin获取最大最小元素索引。
摘要由CSDN通过智能技术生成

本文通过对以下题目进行分析与解答,从而了解Numpy的用法。

其中第一节为基本知识介绍,第二节为题目解答。

题目如下:

基础知识:

1.numpy中的axis

axis常常出现在numpy对矩阵的操作中,指定不同的axis可以从不同方向(如二维矩阵中,axis=0沿纵向,axis=1沿横向)进行操作。


以下是解题过程中所需用到的函数:

1. numpy.random.normal(分别以loc和scale为均值与标准差,随机生成size个数)

numpy.random.normal(loc=0.0scale=1.0size=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

Mean (“centre”) of the distribution.

scale : float or array_like of floats

Standard deviation (spread or “width”) of the distribution.

size : int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if loc and scale are both scalars. Otherwise, np.broadcast(loc, scale).size samples are drawn.

Returns:

out : ndarray or scalar

Drawn samples from the parameterized normal distribution.

2. scipy.linalg.toeplitz(生成一个第一行向量为c,第一列向量为r的托普利兹矩阵)

scipy.linalg. toeplitz ( cr=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 ( about=None</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值