- 教程
- 介绍
- 环境
- Ndarray 对象(Ndarray Object)
- 数据类型
- 数组属性(Array Attributes)
- 阵列创建例程(Array Creation Routines)
- 来自现有数据的数组(Array from Existing Data)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 广播(Broadcasting)
- 迭代数组(Iterating Over Array)
- 数组操作(Array Manipulation)
- Binary 运算符
- 字符串函数(String Functions)
- 数学函数(Mathematical Functions)
- 算术运算(Arithmetic Operations)
- 统计函数(Statistical Functions)
- 统计函数(Statistical Functions)
- 字节交换(Byte Swapping)
- 副本和视图(Copies & Views)
- 矩阵库(Matrix Library)
- 线性代数(Linear Algebra)
- Matplotlib(Matplotlib)
- 使用Matplotlib的直方图(Histogram Using Matplotlib)
- I/O with NumPy
- 有用的资源
- reshape
- flat
- flatten
- ravel
- transpose
- ndarray.T
- rollaxis
- swapaxes
- broadcast
- broadcast_to
- expand_dims
- squeeze
- concatenate
- stack
- hstack
- vstack
- split
- hsplit
- vsplit
- resize
- append
- insert
- delete
- unique
- bitwise_and
- bitwise_or
- invert
- left_shift
- right_shift
- add()
- multiply()
- center()
- capitalize()
- title()
- lower()
- upper()
- split()
- splitlines()
- strip()
- join()
- replace()
- decode()
- encode()
- dot
- vdot
- inner
- matmul
- determinant
- solve
- inv
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
矩阵库(Matrix Library)
NumPy包中包含一个Matrix库numpy.matlib 。 该模块具有返回矩阵而不是ndarray对象的函数。
matlib.empty()
matlib.empty()函数返回一个新矩阵而不初始化条目。 该函数采用以下参数。
numpy.matlib.empty(shape, dtype, order)
Where,
Sr.No. | 参数和描述 |
---|---|
1 | shape int或tuple定义新矩阵的形状 |
2 | Dtype 可选的。 输出的数据类型 |
3 | order C或F. |
例子 (Example)
import numpy.matlib
import numpy as np
print np.matlib.empty((2,2))
# filled with random data
它将产生以下输出 -
[[ 2.12199579e-314, 4.24399158e-314]
[ 4.24399158e-314, 2.12199579e-314]]
numpy.matlib.zeros()
此函数返回填充零的矩阵。
import numpy.matlib
import numpy as np
print np.matlib.zeros((2,2))
它将产生以下输出 -
[[ 0. 0.]
[ 0. 0.]]
numpy.matlib.ones()
此函数返回填充1s的矩阵。
import numpy.matlib
import numpy as np
print np.matlib.ones((2,2))
它将产生以下输出 -
[[ 1. 1.]
[ 1. 1.]]
numpy.matlib.eye()
此函数返回一个矩阵,沿对角线元素为1,其他地方为零。 该函数采用以下参数。
numpy.matlib.eye(n, M,k, dtype)
Where,
Sr.No. | 参数和描述 |
---|---|
1 | n 结果矩阵中的行数 |
2 | M 列数,默认为n |
3 | k 对角线指数 |
4 | dtype 输出的数据类型 |
例子 (Example)
import numpy.matlib
import numpy as np
print np.matlib.eye(n = 3, M = 4, k = 0, dtype = float)
它将产生以下输出 -
[[ 1. 0. 0. 0.]
[ 0. 1. 0. 0.]
[ 0. 0. 1. 0.]]
numpy.matlib.identity()
numpy.matlib.identity()函数返回给定大小的Identity矩阵。 单位矩阵是一个方形矩阵,所有对角元素都为1。
import numpy.matlib
import numpy as np
print np.matlib.identity(5, dtype = float)
它将产生以下输出 -
[[ 1. 0. 0. 0. 0.]
[ 0. 1. 0. 0. 0.]
[ 0. 0. 1. 0. 0.]
[ 0. 0. 0. 1. 0.]
[ 0. 0. 0. 0. 1.]]
numpy.matlib.rand()
numpy.matlib.rand()函数返回给定大小的矩阵,其中填充了随机值。
例子 (Example)
import numpy.matlib
import numpy as np
print np.matlib.rand(3,3)
它将产生以下输出 -
[[ 0.82674464 0.57206837 0.15497519]
[ 0.33857374 0.35742401 0.90895076]
[ 0.03968467 0.13962089 0.39665201]]
Note ,矩阵总是二维的,而ndarray是n维数组。 两个对象都是可互换的。
例子 (Example)
import numpy.matlib
import numpy as np
i = np.matrix('1,2;3,4')
print i
它将产生以下输出 -
[[1 2]
[3 4]]
例子 (Example)
import numpy.matlib
import numpy as np
j = np.asarray(i)
print j
它将产生以下输出 -
[[1 2]
[3 4]]
例子 (Example)
import numpy.matlib
import numpy as np
k = np.asmatrix (j)
print k
它将产生以下输出 -
[[1 2]
[3 4]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论