Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
80 views

I'm trying to find the outer product of a large complex-valued vector (of size 91204) to later on find the it's partial trace using np.einsum. However I get the following error: numpy._core....
jnava1612's user avatar
1 vote
1 answer
79 views

Can you explain why this happened? import numpy as np a = np.array([[1,2], [3,4], [5,6] ]) b = np.array([[2,2,2], [2,2,2]]) print(np.einsum(&...
13byte's user avatar
  • 13
0 votes
1 answer
99 views

I have a numpy array A with shape (a, b, c), and another integer array L with shape (a, b). I want to make an array B such that B[i, j, k] = A[L[i, j],j, k] (assume shapes and values of L permit this)....
Danny Duberstein's user avatar
1 vote
1 answer
166 views

I have the following expression that I need to calculate for some matrices: I could of course do this using a for loop, but I'm attempting to use the torch.einsum function to calculate this in a ...
Gummy bears's user avatar
0 votes
1 answer
132 views

I have 3 vectors(numpy arrays in Python) in C++ and in Python, I wish to do the following tensor contraction: import numpy as np import time N_t, N = 400, 400 a = np.random.rand(N_t, 2, 2, N) b = np....
John 's user avatar
  • 29
1 vote
0 answers
157 views

I want to perform the following contraction np.einsum('ijk,kl,jlm', x, y, z, optimize = 'optimal') Testing performance with numpy I know that for my data, the optimal path is almost allways (if this ...
DPurple's user avatar
  • 31
0 votes
1 answer
278 views

I came across some code on Huggingface (in a self-attention module) that uses torch.einsum, which I'm not too familiar with and would like some help interpreting. I've looked through this list of ...
clueless's user avatar
  • 261
2 votes
1 answer
263 views

I need to replace einsum operation with standard numpy operations in the following code: import numpy as np a = np.random.rand(128, 16, 8, 32) b = np.random.rand(256, 8, 32) output = np.einsum('aijb,...
ir0098's user avatar
  • 149
4 votes
1 answer
104 views

I am trying to implement a tensor network kind of calculation using np.einsum. The goal of the calculation is to have a local 2x2 matrix act sequentially on a tensor of size (2,2,2,...,2,2,2) where ...
RKLS's user avatar
  • 41
0 votes
2 answers
87 views

I tried einsum np.einsum but this is giving me error that the output cannot have same letters repeated. np.einsum('aij,aj->aa', vector1, vector2) Also tried np.dot method but that attempt is also ...
Devarapalli Vamsi's user avatar
1 vote
1 answer
136 views

Suppose the tensor and tensor1 are some calculated transformations of an input with the shapes provided in the code snippet. The einsum operation performs Einstein's summation to aggregate the results ...
Ali Khalili's user avatar
6 votes
3 answers
824 views

I am trying to port some code from MATLAB to Python and I am getting much slower performance from Python. I am not very good at Python coding, so any advise to speed these up will be much appreciated. ...
Rushi's user avatar
  • 165
2 votes
1 answer
113 views

I want to make use of the einsum to speed up a code as following: As simple example using a list of 2 (3,3) arrays called dcx: That i created: In [113]: dcx = [np.arange(9).reshape(3,3), np.arange(10,...
Accelerator's user avatar
0 votes
0 answers
249 views

I am trying to optimize my code and I don't know if I am already at the limit. Here is my problem: I am solving the equation of motion for multiple trajectories. What this means is that I have an ...
J.Agusti's user avatar
  • 173
0 votes
1 answer
834 views

I would like to optimize the python code between the 2 perf_counter functions. By using cupy I already obtained substantial improvement compared to numpy. I was asking myself if there is some ...
Indiano's user avatar
  • 712
0 votes
2 answers
167 views

Is it possible to invert this einsum operation so I get back the input psi4d from it's output psi1 and psi2? psi1 = np.einsum('jqik->ij', psi4d) psi2= np.einsum('kiqj->ij', psi4d)...
Luis ALberto's user avatar
3 votes
1 answer
535 views

I have two 2-d tensors, which align via broadcasting, so if I add/subtract them, I incur a huge 3-d tensor. I don't really need that though, since I'll be performing a mean on one dimension. In this ...
Josh.F's user avatar
  • 3,806
1 vote
1 answer
417 views

Let T and L be two batches of matrices (MxN) and a function f(ti,lj) that calculates a score for matrices ti and lj. For instance, if T, L= torch.rand(4,3,2), torch.rand(4,3,2) # T = tensor([[[0.0017,...
Celso França's user avatar
1 vote
0 answers
78 views

I want to modify this einsum to be more flexible. Right now it's doing a matrix multiplication of the last two dimensions of A against the last 3 of B: tf.einsum("...xp,...pyz->...xyz", A,...
cgreen's user avatar
  • 361
0 votes
0 answers
229 views

I have converted this python eimsum expression psi_p = np.einsum('ij...,j...->i...', exp_p, psi_p) to c++ like this: int io=0; `for (i=0; i < 4; i++){ ikauxop=i*nd; for (j=...
Luis ALberto's user avatar
1 vote
0 answers
808 views

Let's say you use einsum to calculate the slope and intercept in a simple regression as follows: slope = (np.einsum('ij,ij->i', y_norm, x_norm) / np.einsum('ij,ij->i', x_norm, x_norm))...
Victor Roos's user avatar
1 vote
1 answer
1k views

I have two PyTorch tensors. One is rank three and the other is rank four. Is there a way to get it so that it produce the rank and shape of the first tensor? For instance in this cross-attention bit: ...
MScottWaller's user avatar
  • 3,603
0 votes
1 answer
200 views

I am trying to calculate a vectorised nested sum (so effectively doing a separate calculation for each row k) The fastest way I have come up with is to define a lower triangular matrix of ones to ...
Will's user avatar
  • 369
1 vote
1 answer
134 views

I have the following einsum expressions: np.einsum("abc,ab->ac",a,b) np.einsum("abc,abd->dc", a, b) That I would need to convert to standard numpy operations. Can anyone help ...
Miko Miko's user avatar
3 votes
1 answer
1k views

I'm trying to optimize a particular piece of code to calculate the mahalanobis distance in a vectorized manner. I have a standard implementation which used traditional python multiplication, and ...
RocketSocks22's user avatar

1
2 3 4 5 6