Method: Numo::NArray#tril!

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

#tril!(k = 0) ⇒ Object

Lower triangular matrix. Fill the self elements above the k-th diagonal with zero.



1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
# File 'lib/numo/narray/extra.rb', line 1025

def tril!(k=0)
  if ndim < 2
    raise NArray::ShapeError, "must be >= 2-dimensional array"
  end
  if contiguous?
    idx = triu_indices(k+1)
    *shp,m,n = shape
    reshape!(*shp,m*n)
    self[false,idx] = 0
    reshape!(*shp,m,n)
  else
    store(tril(k))
  end
end