给出两组 - d维点.如何在Matlab中最有效地计算成对平方欧氏距离矩阵?
符号:
集合1由(numA,d)-matrix 给出A,集合2由(numB,d)-matrix 给出B.得到的距离矩阵应为格式(numA,numB).
示例点:
d = 4; % dimension
numA = 100; % number of set 1 points
numB = 200; % number of set 2 points
A = rand(numA,d); % set 1 given as matrix A
B = rand(numB,d); % set 2 given as matrix B
Run Code Online (Sandbox Code Playgroud) I want to realize component-wise matrix multiplication in MATLAB, which can be done using numpy.einsum in Python as below:
import numpy as np
M = 2
N = 4
I = 2000
J = 300
A = np.random.randn(M, M, I)
B = np.random.randn(M, M, N, J, I)
C = np.random.randn(M, J, I)
# using einsum
D = np.einsum('mki, klnji, lji -> mnji', A, B, C)
# naive for-loop
E = np.zeros(M, N, J, I)
for i in range(I):
for j …Run Code Online (Sandbox Code Playgroud) matlab sum multidimensional-array elementwise-operations numpy-einsum