等价于np.asarray(x).ravel()
x = np.matrix(np.arange(12).reshape((3,4))); x
matrix([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
x.getA1()
array([ 0, 1, 2, ..., 9, 10, 11])
Example from official site of numpy
本文详细介绍了使用NumPy进行矩阵操作的方法,特别是如何利用np.matrix和相关函数如np.arange、np.reshape将数据转换为矩阵形式,并通过x.getA1()等函数实现矩阵的扁平化处理,对于理解NumPy中矩阵与数组的转换非常有帮助。
等价于np.asarray(x).ravel()
x = np.matrix(np.arange(12).reshape((3,4))); x
matrix([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
x.getA1()
array([ 0, 1, 2, ..., 9, 10, 11])
Example from official site of numpy
2822
2万+

被折叠的 条评论
为什么被折叠?