Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将数据形状从(A,B)翻转到(B,A)_Python_Python 3.x_Numpy - Fatal编程技术网

Python 如何将数据形状从(A,B)翻转到(B,A)

Python 如何将数据形状从(A,B)翻转到(B,A),python,python-3.x,numpy,Python,Python 3.x,Numpy,使用numpy.flip,这可能很容易做到,但它会翻转数组中的所有元素,而不是顺序 data_emg = raw_emg._data * 1e6 print('Data shape =', data_emg.shape) 输出为: Data shape = (3, 5759600) 我希望它是: Data shape = (5759600, 3) 您需要执行转置操作 n = np.array([[1,2,3],[2,3,4]]) print(n.shape) # (2, 3) # usi

使用
numpy.flip
,这可能很容易做到,但它会翻转数组中的所有元素,而不是顺序

data_emg = raw_emg._data * 1e6
print('Data shape =', data_emg.shape)
输出为:

Data shape = (3, 5759600)
我希望它是:

Data shape = (5759600, 3)

您需要执行转置操作

n = np.array([[1,2,3],[2,3,4]])
print(n.shape)
# (2, 3)

# using np.transpose
nT = np.transpose(n)
print(nT.shape)
# (3, 2)

# or alternate way
nT = n.T
print(nT.shape)
# (3, 2)

您可以使用“.T”转换输入。要在代码中保存行,只需在打印时提供:

data_emg = raw_emg._data * 1e6
print('Data shape =', data_emg.T.shape)
或者在代码中需要时将其转置:

data_emg = data_emg.T

虽然你所写的可能回答了这个问题,但是它确实显得有点不足,并且可能会让其他用户感到困惑。你能详细说明你的答案吗?这样答案就更清楚、更容易理解了?这将提供更好的答案,并帮助未来用户了解问题是如何解决的。