ruby-numo / numo-narray

Ruby/Numo::NArray - New NArray class library
http://ruby-numo.github.io/narray/
BSD 3-Clause "New" or "Revised" License
413 stars 41 forks source link

[Feature Request] diagonal= #190

Open kojix2 opened 3 years ago

kojix2 commented 3 years ago

Expected behavior

a = Numo::Int32.new(3,3).seq
a.diagonal = 0
a
# [[0, 1, 2], 
#  [3, 0, 5], 
#  [6, 7, 0]]

Actual behavior

Error

(irb):4:in `<main>': undefined method `diagonal=' for Numo::Int32#shape=[3,3] (NoMethodError)
[[0, 1, 2], 
 [3, 4, 5], 
 [6, 7, 8]]:Numo::Int32
Did you mean?  diagonal

workaround

a = Numo::Int32.new(3,3).seq
b = a.diagonal
b.store 0
a
# [[0, 1, 2], 
#  [3, 0, 5], 
#  [6, 7, 0]]
kojix2 commented 3 years ago

hmm,

a = Numo::Int32.new(3,3).seq
a.diagonal.fill(0)