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

Ignore dimension when using np.einsum

I use np.einsum to calculate the flow of material in a graph (1 node to 4 nodes in this example). The amount of flow is given by amount (amount.shape == (1, 1, 2) the dimensions define certain criteria, let's call them a, b, c). The boolean matrix…
orange
  • 7,755
  • 14
  • 75
  • 139
0
votes
2 answers

How can I speed up the performance by using numpy einsum and numexpr in calculating kernel functions?

I am trying to define a few of famous kernels like RBF, hyperbolic tangent, Fourier and etc for svm.SVR method in sklearn library. I started working on rbf (I know there's a default kernel in svm for rbf but I need to define one to be able to…
Masoud Masoumi Moghadam
  • 1,094
  • 3
  • 23
  • 45
0
votes
1 answer

Fastest way to determine if two points are closest to one another

My problems consists of the following: I am given two pairs angles (in spherical coordinates) which consists of two parts--an azimuth and a colatitude angle. If we extend both angles (thereby increasing their respective radii) infinitely to make a…
Artemis F
  • 72
  • 3
  • 4
  • 19
0
votes
1 answer

Ultimate flexibility with einsum ellipses

I have a question about einsum ellipsis that I thought would be somewhere on StackExchange for sure, but somehow I can't seem to find. Essentially I have some code which does lots of matrix and vector contractions using numpy's einsum. The input is…
Wolpertinger
  • 1,169
  • 2
  • 13
  • 30
0
votes
0 answers

Using numpy einsum to perform high dimensional subtraction broadcasting

I'm having troubles in using a broadcasting subtraction. My problem is the following. I have an array x of shape [L,N], where L is an integer and N is the number of variables of my problem. I need to compute a [L,N,N] array where at each element…
linello
  • 8,451
  • 18
  • 63
  • 109
0
votes
0 answers

Vectorizing multidimensional matrix products with numpy (einsum)

I would like to perform a series of rotations with mxm arrays on a series nxm matrices in a vectorized fashion (1000xmxm dot 1000xnxm --> 1000xnxm). This question seems to have the answer if my nxm matrices were 1xm vectors, but unfortunately they…
0
votes
1 answer

Einsum very slow to compute c distance

I'm computing mahalanobis distance via np.einsum: np.einsum('nj,jk,nk->n', delta, VI, delta) where VI, the covariance matrix's inverse, is 783 x 783 and delta is 6000 x 783. This line takes 10s on my 2016 Macbook Pro to execute. How can I make this…
saad
  • 1,225
  • 15
  • 31
0
votes
1 answer

Optimize Einstein Summation with Repeating Matrices but Different Subscript

Disclaimer: I did though about posting to math stack-exchange or some kind. But I heard from my math-major friends that they don't really use Einstein Summation a lot, but I do know machine learning uses a lot of that. Therefore I posted this…
ZisIsNotZis
  • 1,570
  • 1
  • 13
  • 30
0
votes
1 answer

Numpy einsum_path reports more FLOP and "speeddown"

For the topic np.einsum, I already read a bunch of discussions at: Why is numpy's einsum faster than numpy's built in functions Is there a numpy function to get the sum of sub matrices? In order to understand more about why is np.eimsum faster…
ZisIsNotZis
  • 1,570
  • 1
  • 13
  • 30
0
votes
2 answers

Numpy - Find 3-d distance to a testpoint for all gridpoints on 3-d grid

I tried np.hypot() and np.linalg.norm() but both of them have some issues (at least how I am using thm). I am pretty sure np.hypot can only calculate 2-d distance. If I have a test point P (1,1,1) and a grid point G (3,3,3), then the returned value…
amchugh89
  • 1,276
  • 1
  • 14
  • 33
0
votes
0 answers

Are there any known differences between einsum in python2 vs. python3?

Are there any known differences between einsum in Python2 and Python3? https://github.com/tscohen/GrouPy I was trying to run the code for Tensorflow here, and get a mismatch File…
0
votes
3 answers

numpy dot product of sub array?

I have two ndarray like n1 = np.array([1,2,3,4]) n2 = np.array([1,2,3,4]) While dot product of them can done easily with np.dot(n1, n2), which gives 30 as the right answer. What if I need the dot to be operated on two subarrays from n1 and n2, e.g.…
dofine
  • 863
  • 1
  • 8
  • 20
0
votes
1 answer

Speed difference in np.einsum

I noticed that np.einsum is faster when it reduces one dimension import numpy as np a = np.random.random((100,100,100)) b = np.random.random((100,100,100)) %timeit np.einsum('ijk,ijk->ijk',a,b) # 100 loops, best of 3: 3.83 ms per loop %timeit…
Jürg W. Spaak
  • 2,057
  • 1
  • 15
  • 34
0
votes
1 answer

How to go from np.tensordot to np.einsum

What I have in the code I was given is something like: C = np.tensordot(B, A, axes = (0,0)) A is a (20L, 50L) and B is (20L, 20L) I was supposed to change since someone told me it would be faster with np.einsum, but I guess I don't fully understand…
Iara
  • 1
  • 1
0
votes
1 answer

how to use batch_tensordot in theano like numpy.einsum

I have a tensor3 with shape (3, 4, 5) and another tensor4 with shape (3, 4, 7, 5). In numpy, result = np.einsum("ijk, ijmk->ijm", tensor3, tensor4) print result.shape (3, 4, 7) but in theano , how to do it .
Hungry fool
  • 27
  • 1
  • 6
1 2 3
16
17