在python中有两个稀疏矩阵(a和b),它们具有以下维度:
a = <240760x2177930 sparse matrix of type '<class 'numpy.float64'>'
with 1127853 stored elements in Compressed Sparse Row format>
和
b = <240760x2177930 sparse matrix of type '<class 'numpy.float64'>'
with 439
对于numpy,我可以这样做一个简单的矩阵乘法:
a = numpy.ones((3, 2))
b = numpy.ones((2, 1))
result = a.dot(b)
但是,这不适用于PyTorch:
a = torch.ones((3, 2))
b = torch.ones((2, 1))
result = torch.dot(a, b)
此代码引发以下错误:
RuntimeError:一维张量,但得到二维张量和二维张量
如何在PyTorch中执行矩阵乘法?
我是Python的新手。我在做矩阵乘法时遇到了麻烦。我有两个列表:
A =[3.0,3.0]
# 1 by 2 matrix
B =[[ 50.33112583, -49.66887417],
[-49.66887417, 50.33112583]]
# 2 by 2 matrix
Result should be :
# 1 by 2 matrix
c = [1.9867549668874176, 1.986754966887446]
Right now
如何以更直接的方式做标记为# <----的行?
在程序中,x的每一行都是一个点的坐标,rot_mat[0]和rot_mat[1]是两个旋转矩阵。该程序按每个旋转矩阵旋转x。
改变每个旋转矩阵和坐标之间的乘法顺序是很好的,如果这会让事情变得更简单的话。我想让x的每一行或结果表示一个点的坐标。
结果应该与检查结果匹配。
程序:
# Rotation of coordinates of 4 points by
# each of the 2 rotation matrices.
import numpy as np
from scipy.stats import special_ortho_