Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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 can';t让numpy.transpose在外观上似乎是数组的对象上进行操作?_Python_Arrays_Numpy_Transpose - Fatal编程技术网

Python can';t让numpy.transpose在外观上似乎是数组的对象上进行操作?

Python can';t让numpy.transpose在外观上似乎是数组的对象上进行操作?,python,arrays,numpy,transpose,Python,Arrays,Numpy,Transpose,下面的代码获取一个列表列表,该列表按3行14列排列,并将其转换为数组。然而,numpy.flip和numpy.transpose的应用程序似乎对新数组没有任何作用,尽管可以识别形状……不管“形状”怎么说,这是不是没有正确格式化为3x14数组 fitarray = numpy.array(listoflists) print 'original' print fitarray print 'shape:', fitarray.shape #reverse order in array nump

下面的代码获取一个列表列表,该列表按3行14列排列,并将其转换为数组。然而,numpy.flip和numpy.transpose的应用程序似乎对新数组没有任何作用,尽管可以识别形状……不管“形状”怎么说,这是不是没有正确格式化为3x14数组

fitarray = numpy.array(listoflists)

print 'original'
print fitarray
print 'shape:', fitarray.shape

#reverse order in array
numpy.flipud(numpy.fliplr(fitarray))

print 'after flipping'
print fitarray
print 'shape:' fitarray.shape

numpy.transpose(fitarray)

print 'after transpose'
print fitarray
print 'shape:' fitarray.shape
以下是上述代码的输出:

原创的

[[ 1.          1.          0.75922332  0.72510804  0.60655371  0.61518896
   0.43338281  0.31000672  0.36051202  0.29079866  0.28775219  0.41336631
   0.53799258  0.52036007]
 [ 0.46761031  0.9629559   1.          1.          1.          1.
   0.95181012  0.90766551  0.88126941  0.88357832  0.90511121  0.95506566
   0.99609776  1.        ]
 [ 0.55385467  0.91574368  0.78931241  0.83173184  0.87563584  0.9592057
   1.          1.          1.          1.          1.          1.          1.
   0.99809394]]

shape: (3, 14)
翻转后

[[ 1.          1.          0.75922332  0.72510804  0.60655371  0.61518896
   0.43338281  0.31000672  0.36051202  0.29079866  0.28775219  0.41336631
   0.53799258  0.52036007]
 [ 0.46761031  0.9629559   1.          1.          1.          1.
   0.95181012  0.90766551  0.88126941  0.88357832  0.90511121  0.95506566
   0.99609776  1.        ]
 [ 0.55385467  0.91574368  0.78931241  0.83173184  0.87563584  0.9592057
   1.          1.          1.          1.          1.          1.          1.
   0.99809394]]

shape: (3, 14)
转置后

[[ 1.          1.          0.75922332  0.72510804  0.60655371  0.61518896
   0.43338281  0.31000672  0.36051202  0.29079866  0.28775219  0.41336631
   0.53799258  0.52036007]
 [ 0.46761031  0.9629559   1.          1.          1.          1.
   0.95181012  0.90766551  0.88126941  0.88357832  0.90511121  0.95506566
   0.99609776  1.        ]
 [ 0.55385467  0.91574368  0.78931241  0.83173184  0.87563584  0.9592057
   1.          1.          1.          1.          1.          1.          1.
   0.99809394]]

shape: (3, 14)

您需要根据

例如:

In [182]:

a = np.random.randn(3*14).reshape(3,14)
a
Out[182]:
array([[-1.09047556, -0.03717911,  1.56770073, -0.44577998,  1.89357885,
        -0.53837911,  0.74492976,  0.55248619,  1.19553176, -0.90725472,
         1.33540847, -0.36895309, -0.1392841 ,  0.21324307],
       [ 0.95891412,  0.0810524 , -0.29181996,  0.2275121 ,  1.06491463,
        -0.94156398,  0.04786322,  0.15859003,  0.06085846, -0.8113653 ,
        -0.64495641,  0.03964511, -0.36936448, -1.21301754],
       [-0.1486475 ,  0.61538289, -0.42302942,  0.46333247,  1.65154601,
        -0.16310981,  0.09809179, -0.37837943,  0.98993927,  0.1095821 ,
        -0.69703357, -0.62647274,  1.05738354,  0.01542917]])

In [185]:

b = np.transpose(a)
print(a.shape, b.shape)
(3, 14) (14, 3)

In [189]:

a_copy = a.copy()
b = np.flipud(np.fliplr(a))
print((a_copy == a).all())
print((b == a).all())
True
False

呃。你不需要分配np运算的结果吗?