I have a GeoTIFF file which when imported using rasterio get flipped on the y-axis, and now I am trying to rotate this GeoTIFF file using NumPy rotate, it gives an error (Axes=(0, 1) out of range for array of ndim=0)

rf = rasterio.open(r'C:\Users\NESAC\tp.geotif')
fig, ax= plt.subplots(1,1)
show(rf, ax = ax, title = 'temperature')
rot = np.rot90(rf, k=3)




Check your array dimensions using rf.shape. Try to skip axis parameter:

import numpy as np

a = np.array([[1,2], [3,4], [5,6]])
print(a, '\n')

b = np.rot90(a)
print(b, '\n')

c = np.rot90(a, axes=(0, 1))

error = np.rot90(a, k=1, axes=(1, 2))

Traceback (most recent call last):
  File "/tmp/sessions/635a4f4228bcccc0/main.py", line 8, in <module>
    error = np.rot90(a, k=1, axes=(1, 2))
  File "/usr/local/lib/python3.6/dist-packages/numpy/lib/function_base.py", line 128, in rot90
    .format(axes, m.ndim))
ValueError: Axes=(1, 2) out of range for array of ndim=2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.