我建议您使用 numpy 来安装它
在此站点的 Windows 上:
http://sourceforge.net/projects/numpy/files/NumPy/
一些示例如何使用它。
import numpy as np
我们将创建一个数组,我们将其命名为 mat
>>> mat = np.random.randn(2,3)
>>> mat
array([[ 1.02063865, 1.52885147, 0.45588211],
[-0.82198131, 0.20995583, 0.31997462]])
使用动词“T”转置数组
>>> mat.T
array([[ 1.02063865, -0.82198131],
[ 1.52885147, 0.20995583],
[ 0.45588211, 0.31997462]])
使用 \verb"reshape" 方法改变任何数组的形状
>>> mat = np.random.randn(3,6)
array([[ 2.01139326, 1.33267072, 1.2947112 , 0.07492725, 0.49765694,
0.01757505],
[ 0.42309629, 0.95921276, 0.55840131, -1.22253606, -0.91811118,
0.59646987],
[ 0.19714104, -1.59446001, 1.43990671, -0.98266887, -0.42292461,
-1.2378431 ]])
>>> mat.reshape(2,9)
array([[ 2.01139326, 1.33267072, 1.2947112 , 0.07492725, 0.49765694,
0.01757505, 0.42309629, 0.95921276, 0.55840131],
[-1.22253606, -0.91811118, 0.59646987, 0.19714104, -1.59446001,
1.43990671, -0.98266887, -0.42292461, -1.2378431 ]])
我们可以使用 \verb"shape" 属性来改变变量的形状。
>>> mat = np.random.randn(4,3)
>>> mat.shape
(4, 3)
>>> mat
array([[-1.47446507, -0.46316836, 0.44047531],
[-0.21275495, -1.16089705, -1.14349478],
[-0.83299338, 0.20336677, 0.13460515],
[-1.73323076, -0.66500491, 1.13514327]])
>>> mat.shape = 2,6
>>> mat.shape
(2, 6)
>>> mat
array([[-1.47446507, -0.46316836, 0.44047531, -0.21275495, -1.16089705,
-1.14349478],
[-0.83299338, 0.20336677, 0.13460515, -1.73323076, -0.66500491,
1.13514327]])