2

# Axes must be different.

Package:
numpy
18118
Exception Class:
ValueError

## Raise code

``````    axes = tuple(axes)
if len(axes) != 2:
raise ValueError("len(axes) must be 2.")

m = asanyarray(m)

if axes[0] == axes[1] or absolute(axes[0] - axes[1]) == m.ndim:
raise ValueError("Axes must be different.")

if (axes[0] >= m.ndim or axes[0] < -m.ndim
or axes[1] >= m.ndim or axes[1] < -m.ndim):
raise ValueError("Axes={} out of range for array of ndim={}."
.format(axes, m.ndim))

k %= 4``````
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

## Ways to fix

4

Explanation: the function rot90 rotates an an array by 90 degrees in the plane specified by axes.

the rotation direction is from the first towards the second axis. This specified in the axes argument.

The key rule to the axes argument is they must be different and they should well define the axes of the given array (i.e the difference between the two axes must be less than the shape the array.)

Code to reproduce the error:

```import numpy as np
m = np.array([[1,2],[3,4]], int)
print(m)
rotated =np.rot90(m,k=1, axes=(0, 2))
# here the axes go beyond the 2D shape of the given array. The same error happens when they are the same
print(rotated)

```

Fixed version of the code

```import numpy as np
m = np.array([[1,2],[3,4]], int)
print(m)
rotated =np.rot90(m,k=1, axes=(0, 1))
print(rotated)
```

More details on usage of this function is found here

May 19, 2021
kellemnegasi 31.6k