Numpy 3D 数组到 2D 行主数组
Numpy 3D array to 2D row major array
我有一个尺寸为 (28, 28, 60000) 的 numpy 数组,包含 60000 张 28x28 图像,以像素亮度表示。我正在尝试对其进行转换,以便我拥有一个 60000 x 784 阵列,其中 784 代表行主要格式的原始 28x28 图像。我该怎么做呢?我假设我使用 numpy.reshape,但我不确定它是如何重新排列的。示例:
[[1,2], [[1,2,3,4],
[3,4]] [5,6,7,8]]
... ->
[[5,6],
[7,8]]
试着尝试这样的事情:
a = np.arange(6).reshape((3, 2))
b = np.reshape(a, (1, 6))
print a
print b
a =
[[0 1]
[2 3]
[4 5]]
b = [[0 1 2 3 4 5]]
此代码:
import numpy
a = numpy.array([[[1,2],[3,4]],[[5,6],[7,8]]])
print(numpy.reshape(a, (2,4)))
Returns:
[[1 2 3 4]
[5 6 7 8]]
我有一个尺寸为 (28, 28, 60000) 的 numpy 数组,包含 60000 张 28x28 图像,以像素亮度表示。我正在尝试对其进行转换,以便我拥有一个 60000 x 784 阵列,其中 784 代表行主要格式的原始 28x28 图像。我该怎么做呢?我假设我使用 numpy.reshape,但我不确定它是如何重新排列的。示例:
[[1,2], [[1,2,3,4],
[3,4]] [5,6,7,8]]
... ->
[[5,6],
[7,8]]
试着尝试这样的事情:
a = np.arange(6).reshape((3, 2))
b = np.reshape(a, (1, 6))
print a
print b
a =
[[0 1]
[2 3]
[4 5]]
b = [[0 1 2 3 4 5]]
此代码:
import numpy
a = numpy.array([[[1,2],[3,4]],[[5,6],[7,8]]])
print(numpy.reshape(a, (2,4)))
Returns:
[[1 2 3 4]
[5 6 7 8]]