Here are the examples of the python api numpy.nxarray taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Example 1
Project: robothon Source File: extras.py
def compress_rowcols(x, axis=None):
"""Suppress the rows and/or columns of a 2D array that contains
masked values.
The suppression behavior is selected with the `axis`parameter.
- If axis is None, rows and columns are suppressed.
- If axis is 0, only rows are suppressed.
- If axis is 1 or -1, only columns are suppressed.
Parameters
----------
axis : int, optional
Axis along which to perform the operation.
If None, applies to a flattened version of the array.
Returns
-------
compressed_array : an ndarray.
"""
x = asarray(x)
if x.ndim != 2:
raise NotImplementedError, "compress2d works for 2D arrays only."
m = getmask(x)
# Nothing is masked: return x
if m is nomask or not m.any():
return x._data
# All is masked: return empty
if m.all():
return nxarray([])
# Builds a list of rows/columns indices
(idxr, idxc) = (range(len(x)), range(x.shape[1]))
masked = m.nonzero()
if not axis:
for i in np.unique(masked[0]):
idxr.remove(i)
if axis in [None, 1, -1]:
for j in np.unique(masked[1]):
idxc.remove(j)
return x._data[idxr][:,idxc]