What is the difference between

```
import numpy as np
np.dot(a,b)
```

and

```
import numpy as np
np.inner(a,b)
```

all examples I tried returned the same result. Wikipedia has the same article for both?! In the description of `inner()`

it says, that its behavior is different in higher dimensions, but I couldn't produce any different output. Which one should I use?

For 2-D arrays it is equivalent to matrix multiplication, and for 1-D arrays to inner product of vectors (without complex conjugation). For N dimensions it is a sum product over the

last axisof a and thesecond-to-lastof b:

Ordinary inner product of vectors for 1-D arrays (without complex conjugation), in higher dimensions a sum product over the

last axes.

(Emphasis mine.)

As an example, consider this example with 2D arrays:

```
>>> a=np.array([[1,2],[3,4]])
>>> b=np.array([[11,12],[13,14]])
>>> np.dot(a,b)
array([[37, 40],
[85, 92]])
>>> np.inner(a,b)
array([[35, 41],
[81, 95]])
```

Thus, the one you should use is the one that gives the correct behaviour for your application.

**Performance testing**

(Note that I am testing only the 1D case, since that is the only situation where `.dot`

and `.inner`

give the same result.)

```
>>> import timeit
>>> setup = 'import numpy as np; a=np.random.random(1000); b = np.random.random(1000)'
>>> [timeit.timeit('np.dot(a,b)',setup,number=1000000) for _ in range(3)]
[2.6920320987701416, 2.676928997039795, 2.633111000061035]
>>> [timeit.timeit('np.inner(a,b)',setup,number=1000000) for _ in range(3)]
[2.588860034942627, 2.5845699310302734, 2.6556360721588135]
```

So maybe `.inner`

is faster, but my machine is fairly loaded at the moment, so the timings are not consistent nor are they necessarily very accurate.

`np.dot`

and `np.inner`

are identical for 1-dimensions arrays, so that is probably why you aren't noticing any differences. For N-dimension arrays, they correspond to common tensor operations.

`np.inner`

is sometimes called a "vector product" between a higher and lower order tensor, particularly a tensor times a vector, and often leads to "tensor contraction". It includes matrix-vector multiplication.

`np.dot`

corresponds to a "tensor product", and includes the case mentioned at the bottom of the Wikipedia page. It is generally used for multiplication of two similar tensors to produce a new tensor. It includes matrix-matrix multiplication.

If you're not using tensors, then you don't need to worry about these cases and they behave identically.

inner is not working properly with complex 2D arrays, Try to multiply

and its transpose

```
array([[ 1.+1.j, 4.+4.j, 7.+7.j],
[ 2.+2.j, 5.+5.j, 8.+8.j],
[ 3.+3.j, 6.+6.j, 9.+9.j]])
```

you will get

```
array([[ 0. +60.j, 0. +72.j, 0. +84.j],
[ 0.+132.j, 0.+162.j, 0.+192.j],
[ 0.+204.j, 0.+252.j, 0.+300.j]])
```

effectively multiplying the rows to rows rather than rows to columns

For 1 and 2 dimensional arrays numpy.inner works as transpose the second matrix then multiply. So for:

```
A = [[a1,b1],[c1,d1]]
B = [[a2,b2],[c2,d2]]
numpy.inner(A,B)
array([[a1*a2 + b1*b2, a1*c2 + b1*d2],
[c1*a2 + d1*b2, c1*c2 + d1*d2])
```

I worked this out using examples like:

```
A=[[1 ,10], [100,1000]]
B=[[1,2], [3,4]]
numpy.inner(A,B)
array([[ 21, 43],
[2100, 4300]])
```

This also explains the behaviour in one dimension, `numpy.inner([a,b],[c,b]) = ac+bd`

and `numpy.inner([[a],[b]], [[c],[d]]) = [[ac,ad],[bc,bd]]`

. This is the extent of my knowledge, no idea what it does for higher dimensions.

Similar Questions

I am struggling a little bit with the concept that NumPy is said to be vectorizing its arithmetic array operations: Does it overcome Python's GIL since part of NumPy is implemented in C? Also, how doe

What is the difference between Database and Data Source?

Possible Duplicate: What is the difference between HTML tags DIV and SPAN? I'd like to know the difference between using <span> and <div> when writing a one line text other than the div

what is the difference between inheritance and category in objective-c Both are used for the subclass! So what is difference between them

I have a data set that may contain duplicates. In order to find the duplicates in the dataset I put the indices into a numpy structured array, sort the array, create another array from the unique valu

What is the difference between INNER JOIN and OUTER JOIN? How do LEFT JOIN, RIGHT JOIN, and FULL JOIN fit in?

Just Randomly got this question in my head! Whats the difference between API , Framework and middleware? Essentially all of them provide abstract low level services to apps. In that case why is dot ne

This question already has an answer here: Difference between INNER and OUTER joins 14 answers Difference between inner and outer join. i am using two table and want to fetch data from both tabl

Say I have two 3 dimensional matrices, like so (taken from this matlab example http://www.mathworks.com/help/matlab/ref/dot.html): A = cat(3,[1 1;1 1],[2 3;4 5],[6 7;8 9]) B = cat(3,[2 2;2 2],[10 11;1

I'm a little bit confused, can somebody please explain the main difference between those types of containers: map list set array thanks in advanca(I'm asking about C++)

Let import pyopencl as cl import pyopencl.array as cl_array import numpy a = numpy.random.rand(50000).astype(numpy.float32) mf = cl.mem_flags What is the difference between a_gpu = cl.Buffer(self.ctx

I want to know the difference between setInterval() (or) setTimeout() in DOM and polling in ajax. What is the main difference? If both are same, why the identified by two different names? What is mea

Possible Duplicates: Which LINQ syntax do you prefer? Fluent or Query Expression LINQ: Dot Notation vs Query Expression What is the difference between the two methods of sorting in Linq? Is one bett

New to Django, can someone explain the difference between username=form.cleaned_data['username'] vs username=form.cleaned_data.get('username')

What's the difference between Stroke and Fill drawing in graphics context (iPhone SDK)

Possible Duplicate: INNER JOIN versus WHERE clause — any difference? What is the difference between an INNER JOIN query and an implicit join query (listing multiple tables after the FROM keyword)? F

what's the difference between these retains?: @property (nonatomic, retain) NSString *A_StringToRetain; and NSString *B_StringToRetain; B_StringToRetain = [[MyClass GetStringValue] retain]; Because

What is the difference between cookieSession and cookie in express?

Possible Duplicate: What is the difference between these two javascript functions? I am a newbie to Jquery. A question I have in mind: What is the difference between these two jquery functions? (fun

What is the difference between: import numpy as np A = np.zeros((3,)) and import numpy as np B = np.zeros((1,3)) Thanks for your answer!

This question already has an answer here: Scala list concatenation, ::: vs ++ 3 answers For a scala list, what is the difference between ::: and ++ From doc ::: Adds an element at the beginn

What is the difference between UIImage and UIImageView? Can someone explain it with an example?

What is the difference between these calls?

I was trying to solve the problem on spoj but my answer is not accepting giving wrong answer i want to know difference between these two chunks of code. Spoj accepting this public class Test { public

I am trying to use Python to compute the difference between two text files and print the first value and location where they start to diverge. I am not sure how to use loadtxt: import numpy as np a =

I've got a numpy script that spends about 50% of its runtime in the following code: s = numpy.dot(v1, v1) where v1 = v[1:] and v is a 4000-element 1D ndarray of float64 stored in contiguous memory (v.

What is the difference between Invoke and DynamicInvoke in delegates? Please give me some code example which explain difference between that two methods. Thanks.

What is the difference between the \ and the / when doing streamwriter? e.g. Example 1: Streamwriter sw = new Streamwriter(/test folder/Output/test.txt); and Example 2: Streamwriter sw = new Stream

What the difference between terms 'Isolation Framework' and 'Mocking Framework'?

I am working with 3-dimensional numpy arrays, on which I will ultimately perform PCA. I first flatten the 3-D arrays into 2-D so that I can calculate covariance (and then eigenvalues and eigenvectors)

What is the difference between Claims based authentication vs What is provided by OAuth. I am looking for conceptual difference and not technical difference. When do I choose Claims over OAuth and vic

i want to ask a question. What is the main Difference between extending a class from Activity and ActionbarActivity. Please Explain the major core difference between activity & ActionbarActivity.

what is the Difference between tortoise svn and CollabNetSubversion.....

Is there any difference between these two ? I cannot find any reference for local inner class Here. And many sources have used this term. EG here

I just wanted to know the difference between . operator and :: operator?

Im programming with PYTHON... I have two diferent dates...and I want to know the difference (in days) between them. The format of the date is YYYY-MM-DD To explain myself in a better way... I have a f

The numpy.dot docstring says: For 2-D arrays it is equivalent to matrix multiplication, and for 1-D arrays to inner product of vectors (without complex conjugation). For N dimensions it is a sum prod

What is the difference between interrupt and an event?

This question already has an answer here: Differance between INNER JOIN and WHERE? 2 answers I am curious to learn the difference between selecting from two tables and joining in the WHERE clau

int[] a = new int[]{1,2,3}; int[] b = {1,2,3}; What difference between a and b? Am I right that first is object and 'a' is a link, and second is a primitive type and 'b' is a variable? But what advan

What is the difference between these jQuery code structures, or is there no difference. Are they both an alias for $(document).ready(function(){ and if so, why the dollar in the first code snippet? jQ

It's probably very lame question, but I found no references in C# specification about round brackets. Please point me to spec or msdn if answer on that question will be obvious. What is the inner diff

I have a 60GB SciPy Array (Matrix) I must share between 5+ multiprocessing Process objects. I've seen numpy-sharedmem and read this discussion on the SciPy list. There seem to be two approaches--numpy

What is the difference between TextBox1.Text = null; and TextBox1.Text = ; both clears or nullifies the textbox, but is there any particular difference?

What is the main difference between a inner class and a static nested class in Java? Does design /implementation play a role in choosing any of these?

Possible Duplicate: Difference between Convert.tostring() and .tostring() Hi Carrying on from this question http://stackoverflow.com/questions/3486810/the-difference-between-convert-and-parse Here a

What is the difference between $var= and $var.=? I can't understand the difference between following statements: $querypost .= &showposts=$limit; $querypost .= &paged=$paged;

What is the difference between varchar and nvarchar in SQLite

Can someone please explain the difference between .+ and .+? I have the string: extend cup end table The pattern e.+d finds: extend cup end The pattern e.+?d finds: extend and end I know that + is

Possible Duplicate: Difference between dates in JavaScript I've found myself at a javascript brick wall. I would like to find the difference (in hours and minutes) between two times on two different