NumPy探索

Numpy官网中的介绍:

  • NumPy is the fundamental package for scientific computing with Python. It contains among other things:

    • a powerful N-dimensional array object
    • sophisticated (broadcasting) functions
    • tools for integrating C/C++ and Fortran code
    • useful linear algebra, Fourier transform, and random number capabilities
  • Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.

Numpy是Python的一个科学计算的库,提供了矩阵运算的功能等。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import numpy as np

print(np.version.version)

# numpy.array:多维数组
# 以tuple或list变量为参数产生一维/二维数组
print(np.array((1, 2, 3, 4)))
print(np.array([5, 6, 7, 8], dtype=np.int32))
print(np.array([[1, 3], [5, 6]]))

# numpy.arange:
print(np.arange(8))
print(np.arange(8).reshape(2, 4))

# numpy.linspace(从23中产生3个数)
print(np.linspace(2, 3, 3))

# numpy.zeros,numpy.ones,numpy.eye等构造特定矩阵
print(np.zeros(5))
print(np.ones(5))
print(np.zeros((3, 5)))
print(np.ones((3, 5)))
print(np.eye(3))
八宝粥 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!