ruby-numo / numo-narray

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

[Proposal] Change behavior of [] when ndim > 1 #155

Closed ankane closed 2 years ago

ankane commented 4 years ago

Hi, thanks for this great project!

I wanted to get your thoughts on changing the behavior of [] to match both Ruby arrays and Numpy when ndim > 1. Currently, Numo returns a single value with [] regardless of the number of dimensions. It's easier to demonstrate on a 2d array.

require "numo/narray"

a = Numo::NArray.asarray([[1, 2, 3], [4, 5, 6]])
p a[0] # 1

With Ruby arrays, you get an array back (the entire row).

b = [[1, 2, 3], [4, 5, 6]]
p b[0] # [1, 2, 3]

Same with NumPy.

import numpy as np

x = np.array([[1, 2, 3], [4, 5, 6]])
print(x[0]) # [1 2 3]

I personally find the Ruby array/NumPy behavior much more intuitive. Let me know your thoughts. This change would not be backwards compatible.

kojix2 commented 4 years ago

Hi, ankane !

According to Twitter, Tanaka-san is busy moving from Ibaraki Prefecture to Kanagawa Prefecture these days. :truck: :truck: :truck: I think he will reply when things settle down...

ankane commented 4 years ago

Thanks @kojix2. Was also going to suggest making mean work on integer types, but saw you already suggested it two years ago :) https://github.com/ruby-numo/numo-narray/issues/79

orlando-labs commented 3 years ago

Hi, @kojix2. Hello, @ankane. This proposal needs a bump indeed. Current behaviour is totally counterintuitive. I may contribute with the code, but we all need a permission to implement such breaking changes.

ankane commented 2 years ago

Cleaning up stale issues