flopy.utils.recarray_utils module¶
- create_empty_recarray(length, dtype, default_value=0)[source]¶
Create a empty recarray with a defined default value for floats.
- Parameters
length (int) – Shape of the empty recarray.
dtype (np.dtype) – dtype of the empty recarray.
default_value (float) – default value to use for floats in recarray.
- Returns
r – Recarray of type dtype with shape length.
- Return type
np.recarray
Examples
>>> import numpy as np >>> import flopy >>> dtype = np.dtype([('x', np.float32), ('y', np.float32)]) >>> ra = flopy.utils.create_empty_recarray(10, dtype)
- ra_slice(ra, cols)[source]¶
Create a slice of a recarray
- Parameters
ra (np.recarray) – recarray to extract a limited number of columns from.
cols (list of str) – List of key names to extract from ra.
- Returns
ra_slice – Slice of ra
- Return type
np.recarray
Examples
>>> import flopy >>> raslice = flopy.utils.ra_slice(ra, ['x', 'y'])
- recarray(array, dtype)[source]¶
Convert a list of lists or tuples to a recarray.
- Parameters
array (list of lists) – list of lists containing data to convert to a recarray. The number of entries in each list in the list must be the same.
dtype (np.dtype) – dtype of the array data
- Returns
r – Recarray of type dtype with shape equal to the length of array.
- Return type
np.recarray
Examples
>>> import numpy as np >>> import flopy >>> dtype = np.dtype([('x', np.float32), ('y', np.float32)]) >>> arr = [(1., 2.), (10., 20.), (100., 200.)] >>> ra = flopy.utils.recarray(arr, dtype)