Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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
Python2.7中的向量转置_Python_Python 2.7_Vector_Transpose - Fatal编程技术网

Python2.7中的向量转置

Python2.7中的向量转置,python,python-2.7,vector,transpose,Python,Python 2.7,Vector,Transpose,我想知道如何正确地转置向量。因为我的实现显然不起作用。 这就是我要做的 import numpy as np weights = np.random.random(3) weights.shape (3,) 如果我做转置: np.transpose(weights) np.transpose(weights).shape (3,) 因此,为什么我的重量尺寸不变?多谢各位 np.transpose(weights[np.newaxis]) 或者更简单的方式: weights[np.

我想知道如何正确地转置向量。因为我的实现显然不起作用。 这就是我要做的

import numpy as np
weights = np.random.random(3)

weights.shape
(3,)
如果我做转置:

np.transpose(weights)
np.transpose(weights).shape
(3,)
因此,为什么我的重量尺寸不变?多谢各位

np.transpose(weights[np.newaxis])    
或者更简单的方式:

weights[np.newaxis].T
但是,正如中所指出的,您必须考虑是否有充分的理由以这种方式对其进行转置,因为转置后的1D向量仍然是1D向量

或者更简单的方式:

weights[np.newaxis].T

但是,正如中所指出的,您必须考虑是否有充分的理由将其以这种方式转置,因为转置后的一维向量仍然是一维向量。

谢谢您,保罗。我读了那篇文章,但我不明白它的意思或解决办法。因为,我认为我的问题更接近这个问题,但我仍然不知道如何实现括号。谢谢你,保罗。我读了那篇文章,但我不明白它的意思或解决办法。因为,我认为我的问题更接近这个问题,但我仍然不知道如何实现括号。