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
```

## Links to the raise (1)

https://github.com/numpy/numpy/blob/5f3c3181b5d8db0e430e5f605cc45c4392f04934/numpy/lib/function_base.py#L121## See also in the other packages (2)

(❌️ No answer)

torch/axes-must-be-different/
(❌️ No answer)

dask/axes-must-be-different/
## 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

### Add a possible fix

Please authorize to post fix