ruby-numo/numo-narray

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

ankane opened this issue ยท 4 comments

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.

Hi, ankane !

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

Thanks @kojix2. Was also going to suggest making mean work on integer types, but saw you already suggested it two years ago :) #79

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.

Cleaning up stale issues