Questions tagged [numpy-einsum]

NumPy's `einsum` function implements the Einstein summation convention for multidimensional array objects. Use this tag for questions about how `einsum` can be applied to a particular problem in NumPy, or more questions about how the function works.

NumPy's einsum function implements the Einstein summation convention for multidimensional array objects. This allows many operations involving the multiplication or summation of values along particular axes to be expressed succinctly.

249 questions
0
votes
1 answer

Cannot understand einsum calculation

I'm trying to port some code from python to R (forewarning.. I know far less python than I do R). Anyway I've a complicated einsum command that I need to understand well in order to translate it and I'm having troubles. Based on an answer to…
user2498193
  • 1,072
  • 2
  • 13
  • 32
0
votes
0 answers

Einsum notation to add a vector to every column in the matrix

I have a matrix A of size m X n and vector V of size m X 1 A = [1 2 3 4 5 6 8 9 10] V = [1 2 3] I want to compute A + V i.e., add the vector to every column of A A = [2 3 4 6 7 8 11 12 13] I have been reading…
0
votes
1 answer

Translating np.einsum() to MATLAB

I am having trouble understanding the documentation of np.einsum(). How are subscripts interpreted? I am trying to write np.einsum('a...c,b...c', Y, conj(Y)) where Y is a matrix of shape C, F, T on the original python. Also, due to previous…
havakok
  • 1,185
  • 2
  • 13
  • 45
0
votes
0 answers

Implementing numpy einstein summation for sum of dot products

I need to optimize an algorithm, which needs to be fast as possible, for now, its a basic sum over the dot products of 2 vectors problem, but I think my solution is a bit redundant, and Einstein notation can get much faster results. First, I had a…
Olca Orakcı
  • 372
  • 3
  • 12
0
votes
1 answer

Python Numpy einsum klij->kijl and kijl->klij what do they mean?

I am trying to understand the following code from https://github.com/rezazad68/BCDU-Net/blob/master/Retina%20Blood%20Vessel%20Segmentation/evaluate.py: patches_imgs_test = np.einsum('klij->kijl', patches_imgs_test) and also the…
Stoner
  • 846
  • 1
  • 10
  • 30
0
votes
0 answers

Combine two 3d numpy arrays to 2d arrays with einsum or broadcasting?

I have loop to multiplying slices from two 3-d numpy arrays to produce a 2-d array. I suspect there must be a more efficient way to do this with broadcasting or einsum, but I can't figure it out. A = np.array([[[ 9.99948603e-01, -9.99948603e-01, …
fgregg
  • 3,173
  • 30
  • 37
0
votes
2 answers

How to parse numpy.einsum for two three-dimensional arrays "fid,fi->fd"

I can wrap my head around the two-dimensional examples, and I have an intuition about 'repeated' dimensions causing multiplication, and omitted dimensions in the explicit output causing summation across the dimension. But I'm trying to parse an…
0__
  • 66,707
  • 21
  • 171
  • 266
0
votes
0 answers

How to use numpy.einsum to blend two frames?

Goal I want to use numpy.einsum to blend two frames together. The reason I really want to use einsum is because I would like to be able to understand how it works and how it can be applied. Problem I have two frames, a "red" frame and a "green"…
MuadDev
  • 392
  • 3
  • 12
0
votes
1 answer

numpy.einsum('ij,ji', a, b) performance issue

Could someone expain, why numpy.einsum('ij,ji', A, B) is much slower than numpy.einsum('ij,ij', A, B), as it is shown below? In [1]: import numpy as np In [2]: a = np.random.rand(1000,1000) …
mrkwjc
  • 1,080
  • 8
  • 17
0
votes
1 answer

How do I rotate timeseries in a 5-d numpy matrix?

I am trying to rotate some seismic data held in a numpy nd-array. This array has dimensions (N-receiver, M-sources,3-source_channels, 3-receiver channels, K-time channels). I know how to set up the rotation if applied to a single time stamp (t_i)…
0
votes
1 answer

Meaning / equivalent of numpy.einsum expression

I'm desperately trying to find the python built-in equivalent of the following numpy.einsum expression: >>> a = np.array((((1, 2), (3, 4)), ((5, 6), (7, 8)))) >>> a array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) >>> b =…
mini
  • 35
  • 1
  • 7
0
votes
1 answer

Component-wise Product of all Column Combinations of two Matrices

As the title says I want to calculate the component-wise product of all column combinations of two matrices. I already found a solution using numpy.einsum and numpy.hstack. I wonder if there is a solution without hstack. Let a = [a_1, a_2, ..., a_n]…
paul
  • 31
  • 2
0
votes
1 answer

Matrix multiplication but only between specific rows and columns

I have three two matrices A and B, the matrix product I want is diagonal(A.B.A^T), where A^T is transpose of a matrix. The dimensions of the matrices are as follows A - (2^n, n) B - (n, n) where is n is any natural number. I want first row slice…
papabiceps
  • 988
  • 2
  • 18
  • 33
0
votes
0 answers

Matrix left division of stacked arrays using numpy

I'm working on a program to solve the Bloch (or more precise the Bloch McConnell) equations in python. So the equation to solve is: where A is a NxN matrix, A+ its pseudoinverse and M0 and B are vectors of size N. The special thing is that I wanna…
koxx
  • 317
  • 4
  • 15
0
votes
0 answers

optimization scheme of numpy.einsum

What is the optimization scheme of numpy.einsum ? Does it optimize the memory consumption or the CPU or anything else ? I don't see this discussed anywhere. Maybe it's related to the different ‘optimize’ options, that I don't understand
Stéphane
  • 1,389
  • 3
  • 13
  • 34