Closed kojix2 closed 5 years ago
This issue is fixed, https://github.com/ruby-numo/numo-narray/commit/08bc8a77e3d36c3422b99de54a2a547a3def133a But more work is needed to support numpy-like empty array.
>>> a = numpy.arange(6).reshape(2,3)
>>> a[:,0:1]
array([[0],
[3]])
>>> a[:,0:0]
array([], shape=(2, 0), dtype=int64)
Well, is this an empty array with the fixed shape? I had never thought about it. Mathematics is always out of range for my brain size. I think this issue has been resolved. Thank you.
Ah, I Got it.
a = Numo::DFloat.new(2,2).seq
#=> Numo::DFloat#shape=[2,2]
#[[0, 1],
# [2, 3]]
b = a[a<0]
# should be
# => Numo::DFloat#shape=[2,2](empty)
Numo::DFloat.dstack([a,b])
# should be
#=>Numo::DFloat#shape=[2,2]
#[[0, 1],
# [2, 3]]
#or
#=>Numo::DFloat#shape=[2,2,1]
#[[[0],
# [1]],
# [[2],
# [3]]]
I see. This may be useful.
Ah, already supported.
> a = Numo::DFloat.new(2,2).seq
=> Numo::DFloat#shape=[2,2]
[[0, 1],
[2, 3]]
> b = a[0..0,0..]
=> Numo::DFloat(view)#shape=[1,2]
[[0, 1]]
> c = a[[],0..]
=> Numo::DFloat(view)#shape=[0,2][]
> Numo::DFloat.vstack([a,b,c])
=> Numo::DFloat#shape=[3,2]
[[0, 1],
[2, 3],
[0, 1]]
But not well tested.
BTW a[a<0]
should return 1-dimensional array:
> a = Numo::DFloat.new(2,2).seq
=> Numo::DFloat#shape=[2,2]
[[0, 1],
[2, 3]]
> a[a>0]
=> Numo::DFloat(view)#shape=[3]
[1, 2, 3]
> a[a<0]
=> Numo::DFloat(view)#shape=[0][]
BTW a[a<0] should return 1-dimensional array
I see...
a[a>1]
# Numo::DFloat(view)#shape=[2]
# [2, 3]
shoud be 1-dimensional array. OK. I understand.
Hello
I realized that an empty array could not be concatenated.
Ruby Array can concatenate empty arrays.
it seems that the method that change the size of the narray is written in Ruby, not C. Methods related to
concatenate
, such asNumo::SFloat.dstack
, can be very slow when used with Cumo. So, I don't think NArray needs to behave exactly like Ruby Array. It's okay .However, it might be useful to concatenate an empty array.