Arrays

The module escape.core.array provides methods and wrapper classes for creating arrays with floating values, double_array_obj, and with boolean values, mask_array_obj. These array classes allow users to create viewers for existing original numpy.ndarray arrays or create deep copies of them.

Both array classes also support conversion back to numpy arrays, for example using the numpy.asarray method.

Examples:

  1. Wrapping existing numpy array

>>> import escape as esc
>>> import numpy as np
>>> a = np.arange(0, 10, 1, dtype=float) 
>>> w = esc.double_array_obj.convert(a)  
>>> w
  array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])
>>> w.shape
  (10, 1)
>>> a[0:10] = 1
>>> w         
  array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
  1. Deep copy

>>> w = esc.double_array_obj.convert(a, copy=True) 
>>> a[0:10] = 2
>>> w
  array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
escape.core.array.double_array(src, bool copy=False)

Returns an instance of double_array_obj - array of double values, which holds either a copy of source or wraps its data pointer.

Parameters:
src: list or ndarray

Array to be wrapped.

copy: bool

If True the source data will be always copied. If False and source owns its data, i.e. source is not an array view, source array will be not copied. If source doesn’t own its data and copying is not required, the returned object will always hold a source copy.

Returns:

instance of double_array_obj

escape.core.array.mask_array(src, bool copy=False)

Returns an instance of bool_array_obj - array of boolean values, which holds either a copy of source or wraps its data pointer.

Parameters:
src: list or ndarray

Array to be wrapped.

copy: bool

If True the source data will be always copied. If False and source doesn’t own its data, i.e. source is an array view, source array will be not copied. If source doesn’t own its data and copying is not required, the returned object will always hold a source copy.

Returns:

instance of bool_array_obj

class escape.core.array.double_array_obj
static convert(input, bool copy=False)

Static method to create a wrapper of a numpy array or python list with double elements.

Parameters:
input: object - ndarray or list

Array to be wrapped

copy: bool

If True the source data will be always copied. If False and source doesn’t own its data, i.e. source is an array view, source array will be not copied. If source doesn’t own its data and copying is not required, the returned object will always hold a source copy.

Returns:

instance of double_array_obj

shape

Returns shape of ESCAPE array as a tuple (nrows, ncols)

class escape.core.array.mask_array_obj
static convert(input, bool copy=False)

Static method to create a wrapper of a numpy array or python list with boolean elements.

Parameters:
input: object - ndarray or list

Array to be wrapped

copy: bool

If True the source data will be always copied. If False and source owns its data, i.e. source is not an array view, source array will be not copied. If source doesn’t own its data and copying is not required, the returned object will always hold a source copy.

Returns:

instance of mask_array_obj

shape

Returns shape of ESCAPE array as a tuple (nrows, ncols)