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

In Multi-dimensional array products, how do I align axes with and without summation?

What is the best way to do array operations when there are some repeated indices which are summed over AND others which are not? It seems like I may have to use einsum for these operations, but it would be better if there was a tensordot…
Will Martin
  • 993
  • 6
  • 18
0
votes
1 answer

How to understand the result of this np.einsum('kij',A)?

For example, A = np.arange(24).reshape((2, 3, 4)) print np.einsum('ijk', A) this is still A with no problem. But if I do print np.einsum('kij', A) the shape is (3, 4, 2). Shouldn't it be (4, 2, 3)? The result of print np.einsum('cab', A) shape is…
Crazymage
  • 114
  • 9
0
votes
1 answer

Splitting matrix multiplication using einsum

I have a large data matrix and I want calculate the similarity matrix of that large matrix but due to memory limitation I want to split the calculation. Lets assume I have following: For the example I have taken a smaller matrix data1 =…
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
-1
votes
1 answer

Einsum multiply each row with every one for 3X3X3 array

Hello could someone please help me figure out how to use np.einsum to produce the below code's result. I have a (3,3,3) tensor and I will like to get this results which I got from using two for loops. the code I wrote to produce this output is…
-1
votes
1 answer

What does np.einsum('mk,nk', D, D) do?

I'm reading over someone else's code and am unsure what np.einsum does in this case. print(np.einsum('mk,nk', D, D)) # D is an np array with shape (3, 100) This code outputs an array with shape (3, 3). Any help is appreciated!
-1
votes
1 answer

Parallelize a matmul-like matrix computation (tensor product) in Numpy

I want to implement a tensor Tucker product s.t., Input: B in shape (m, n), C in shape (n, n, n) (cube). Output: Y in shape (m, m, m), s.t. Y_ijk = ∑_{0≤a,b,c
graphitump
  • 631
  • 1
  • 5
  • 13
-1
votes
1 answer

Compute distances between 2 dataframes based on boolean matrix as a mask

I have 2 dataframes where columns are features and rows are different items. import pandas as pd import numpy as np import random random.seed(0) data1 = {'x':random.sample(range(1,100), 4), 'y':random.sample(range(1,100), 4),…
-1
votes
1 answer

How can i vectorize this operation?

I have to execute the below operation several thousand times and it is slowing down my code substantially: T = 50 D = 10 K = 20 x = np.random.randn(T, D) y = np.random.randn(T, K) result = np.zeros((K, D)) for k in range(K): for t in…
Tim Hilt
  • 605
  • 5
  • 23
-2
votes
1 answer

Optimizing Mathematical Calculation

I have a model for four possibilities of purchasing a pair items (purchasing both, none or just one) and need to optimize the (pseudo-) log-likelihood function. Part of this, of course, is the calculation/definition of the pseudo-log-likelihood…
1 2 3
16
17