﻿ NumPy: Create an inner product of two arrays - w3resource

# NumPy: Create an inner product of two arrays

## NumPy Mathematics: Exercise-13 with Solution

Write a NumPy program to create an inner product of two arrays.

Sample Solution:-

Python Code:

``````import numpy as np
x = np.arange(24).reshape((2,3,4))
print("Array x:")
print(x)
print("Array y:")
y = np.arange(4)
print(y)
print("Inner of x and y arrays:")
print(np.inner(x, y))
```
```

Sample Output:

```Array x:
[[[ 0  1  2  3]
[ 4  5  6  7]
[ 8  9 10 11]]

[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]]
Array y:
[0 1 2 3]
Inner of x and y arrays:
[[ 14  38  62]
[ 86 110 134]]
```

Pictorial Presentation:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Getting rid of unwanted characters:

You can get rid of whitespaces or any specific character using strip methods in Python. You can use either plain strip for both sides, lstrip for the left side and rstrip for the right side only.

```str="+++Welcome python+++"
str.strip()

print(str)```

Output:

`+++Welcome python+++`