Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify the index of each dimension as an array and perform assignments #191

Open
kojix2 opened this issue Jul 4, 2021 · 0 comments

Comments

@kojix2
Copy link
Contributor

kojix2 commented Jul 4, 2021

In python's numpy, you can substitute by specifying the indices of the x and y axes.

import numpy as np

a = np.arange(9).reshape(3,3)
x = [0, 1, 2]
y = [2, 0, 1]
c = [1000, 1001, 1002]
a[x, y] = c

a
# array([[   0,    1, 1000],
#        [1001,    4,    5],
#        [   6, 1002,    8]])

The same thing is not possible in Ruby.
What should I do?

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

x = [0, 1, 2]
y = [2, 0, 1]
c = [1000, 1001, 1002]

a[x, y] = c

# Numo::Int32#shape=[3,3]
# [[0, 0, 1000], 
#  [0, 0, 1001], 
#  [0, 0, 1002]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant