np.linalg.norm(x, axis = 1, keepdims=True)
返回什么?
我有一个矩阵np.array([[3.0,4.0],[1, 2]])
。我试图规范化矩阵的每一行。答案应该是np.array([[0.6,0.8],[0.4472136,0.89442719]])
,但我无法理解代码的作用以获得答案。
以下是代码:
x = np.array([[3.0,4.0],[1, 2]])
norms = np.linalg.norm(x, axis = 1, keepdims = True)
x /= norms
此代码应该提供规范化的x,但我不明白np.linalg.norm()
返回的是什么。
答案 0 :(得分:1)
<VirtualHost *:80>
ServerName yii2-members-system.dev
ServerAlias yii2-members-system.dev
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/yii2-members-system/mainsite/web"
ErrorLog "logs/mainsite.yii2-members-system.dev-error_log"
CustomLog "logs/mainsite.yii2-members-system.dev-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName yii2-members-system.dev
ServerAlias admin.yii2-members-system.dev
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/yii2-members-system/backend/web"
ErrorLog "logs/admin.yii2-members-system.dev-error_log"
CustomLog "logs/admin.yii2-members-system.dev-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName yii2-members-system.dev
ServerAlias users.yii2-members-system.dev
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/yii2-members-system/frontend/web"
ErrorLog "logs/users.yii2-members-system.dev-error_log"
CustomLog "logs/users.yii2-members-system.dev-access_log" common
</VirtualHost>
在每一行(对于x)都这样做:
np.linalg.norm(x, axis = 1, keepdims=True)
给出5
np.sqrt(3**2 + 4**2)
给出2.23
此向量np.sqrt(1**2 + 2**2)
则为[5, 2.23]
变量
然后将x中的所有值除以此norms
变量,该变量应为norms
。我希望这有帮助