Method: Numo::NArray#rot90

Defined in:
lib/numo/narray/extra.rb

#rot90(k = 1, axes = [0,1]) ⇒ Object

Rotate in the plane specified by axes.

Examples:

a = Numo::Int32.new(2,2).seq
# => Numo::Int32#shape=[2,2]
# [[0, 1],
#  [2, 3]]

a.rot90
# => Numo::Int32(view)#shape=[2,2]
# [[1, 3],
#  [0, 2]]

a.rot90(2)
# => Numo::Int32(view)#shape=[2,2]
# [[3, 2],
#  [1, 0]]

a.rot90(3)
# => Numo::Int32(view)#shape=[2,2]
# [[2, 0],
#  [3, 1]]


67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/numo/narray/extra.rb', line 67

def rot90(k=1,axes=[0,1])
  case k % 4
  when 0
    view
  when 1
    swapaxes(*axes).reverse(axes[0])
  when 2
    reverse(*axes)
  when 3
    swapaxes(*axes).reverse(axes[1])
  end
end