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
>>> from flopy.utils import create_empty_recarray
>>> dt = np.dtype([('x', np.float32), ('y', np.float32)])
>>> create_empty_recarray(1, dt)
rec.array([(0., 0.)],
          dtype=[('x', '<f4'), ('y', '<f4')])
ra_slice(ra, cols)[source]

Create a slice of a recarray

Deprecated since version 3.5: Use numpy.lib.recfunctions.repack_fields instead

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 numpy as np
>>> from flopy.utils import ra_slice
>>> a = np.core.records.fromrecords([("a", 1, 1.1), ("b", 2, 2.1)])
>>> ra_slice(a, ['f0', 'f1'])
rec.array([('a', 1), ('b', 2)],
          dtype=[('f0', '<U1'), ('f1', '<i4')])
recarray(array, dtype)[source]

Convert a list of lists or tuples to a recarray.

Deprecated since version 3.5: Use numpy.core.records.fromrecords instead

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
>>> dt = np.dtype([('x', np.float32), ('y', np.float32)])
>>> a = [(1., 2.), (10., 20.), (100., 200.)]
>>> flopy.utils.recarray(a, dt)
rec.array([(  1.,   2.), ( 10.,  20.), (100., 200.)],
          dtype=[('x', '<f4'), ('y', '<f4')])