bcolz icon indicating copy to clipboard operation
bcolz copied to clipboard

Fancy indexing does not work with multidimensional carrays

Open MarkR80 opened this issue 7 years ago • 3 comments

Fancy indexing does not appear to work with multidimensional carrays. However, the documentation states that "all the functionality of ndarray.getitem() is supported (including fancy indexing)". How do I retrieve multiple, arbitrary elements from a multidimensional carray?

Example code with bcolz v1.2.1:

import numpy as np

x_range = np.arange(0, 10, 1)
x, y = np.meshgrid(x_range, x_range, indexing='ij')

z = x + y
z_comp = bcolz.carray(z)

index_nz = np.nonzero(z == 5)
index_arg = np.argwhere(z == 5)

print( 'Numpy nonzero:', z[index_nz] )
print( 'Bcolz nonzero:', z_comp[index_nz] )
print( 'Bcolz argument:', z_comp[index_arg] )

Results:

print( 'Numpy nonzero:', z[index_nz] )
Numpy nonzero: [5 5 5 5 5 5]

print( 'Bcolz nonzero:', z_comp[index_nz] )
Traceback (most recent call last):

  File "<ipython-input-66-4bcfef4bdb9c>", line 1, in <module>
    print( 'Bcolz nonzero:', z_comp[index_nz] )

  File "bcolz/carray_ext.pyx", line 1964, in bcolz.carray_ext.carray.__getitem__

  File "bcolz/carray_ext.pyx", line 2000, in bcolz.carray_ext.carray.__getitem__

IndexError: arrays used as indices must be integer (or boolean)


print( 'Bcolz argument:', z_comp[index_arg] )
Traceback (most recent call last):

  File "<ipython-input-67-0f3fba13b36d>", line 1, in <module>
    print( 'Bcolz argument:', z_comp[index_arg] )

  File "bcolz/carray_ext.pyx", line 2000, in bcolz.carray_ext.carray.__getitem__

IndexError: arrays used as indices must be integer (or boolean)```

MarkR80 avatar Sep 28 '18 20:09 MarkR80

For indexing into multidimensional arrays, maybe take a look at zarr (which evolved from bcolz): https://zarr.readthedocs.io/en/stable/tutorial.html#advanced-indexing

On Fri, 28 Sep 2018, 21:28 MarkR80, [email protected] wrote:

Fancy indexing does not appear to work with multidimensional carrays. However, the documentation states that "all the functionality of ndarray. getitem() is supported (including fancy indexing)". How do I retrieve multiple, arbitrary elements from a multidimensional carray?

Example code with bcolz v1.2.1:

import numpy as np

x_range = np.arange(0, 10, 1) x, y = np.meshgrid(x_range, x_range, indexing='ij')

z = x + y z_comp = bcolz.carray(z)

index_nz = np.nonzero(z == 5) index_arg = np.argwhere(z == 5)

print( 'Numpy nonzero:', z[index_nz] ) print( 'Bcolz nonzero:', z_comp[index_nz] ) print( 'Bcolz argument:', z_comp[index_arg] )

Results:

print( 'Numpy nonzero:', z[index_nz] ) Numpy nonzero: [5 5 5 5 5 5]

print( 'Bcolz nonzero:', z_comp[index_nz] ) Traceback (most recent call last):

File "", line 1, in print( 'Bcolz nonzero:', z_comp[index_nz] )

File "bcolz/carray_ext.pyx", line 1964, in bcolz.carray_ext.carray.getitem

File "bcolz/carray_ext.pyx", line 2000, in bcolz.carray_ext.carray.getitem

IndexError: arrays used as indices must be integer (or boolean)

print( 'Bcolz argument:', z_comp[index_arg] ) Traceback (most recent call last):

File "", line 1, in print( 'Bcolz argument:', z_comp[index_arg] )

File "bcolz/carray_ext.pyx", line 2000, in bcolz.carray_ext.carray.getitem

IndexError: arrays used as indices must be integer (or boolean)```

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Blosc/bcolz/issues/382, or mute the thread https://github.com/notifications/unsubscribe-auth/AAq8Qtv463vfdpcizW40cG_gEgrmitu8ks5ufoZvgaJpZM4W_rfk .

alimanfoo avatar Sep 28 '18 21:09 alimanfoo

Thank you for the suggestion. You may want to note in the documentation that fancy indexing is not supported for multidimensional arrays.

MarkR80 avatar Sep 30 '18 23:09 MarkR80

@alimanfoo is correct in that zarr is much better positioned for handling multidimensional arrays than bcolz is. Also, bcolz is mainly in maintenance mode (it has been underfunded for too long), so I guess zarr is a better bet for incorporating new features.

FrancescAlted avatar Oct 01 '18 06:10 FrancescAlted