Fancy indexing does not work with multidimensional carrays
MarkR80 opened this issue · 3 comments
MarkR80 commented
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)```
alimanfoo commented
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, ***@***.***> 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 "<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)```
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#382>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAq8Qtv463vfdpcizW40cG_gEgrmitu8ks5ufoZvgaJpZM4W_rfk>
.
MarkR80 commented
Thank you for the suggestion. You may want to note in the documentation that fancy indexing is not supported for multidimensional arrays.
FrancescAlted commented
@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.