7. Structured arrays wrapping¶
Taking derivatives on structured numpy arrays is not supported by jax
,
so structured arrays are internally wrapped with StructuredArray
.
7.1. StructuredArray¶
- class lsqfitgp.StructuredArray(array)¶
JAX-friendly imitation of a numpy structured array.
It behaves like a read-only numpy structured array, with the exception that you can set a whole field/subfield.
- Parameters:
- arraynumpy array, StructuredArray
A structured array. An array qualifies as structured if
array.dtype.names is not None
.
Notes
The StructuredArray is a readonly view on the input array. When you change the content of a field of the StructuredArray, however, the reference to the original array for that field is lost.
Examples
>>> a = numpy.empty(3, dtype=[('f', float), ('g', float)]) >>> a = StructuredArray(a) >>> a['f'] = numpy.arange(3) # this is allowed >>> a[1] = (0.3, 0.4) # this raises an error
- classmethod from_dataframe(df)¶
Make a Structured array from a DataFrame. Data is not copied.
7.2. Functions¶
- lsqfitgp.asarray(x)¶
Version of numpy.asarray that works with StructuredArray and JAX arrays. If x is not a numpy array, returns a JAX array if possible.
- lsqfitgp.broadcast(*arrays)¶
Version of numpy.broadcast that works with StructuredArray.
- lsqfitgp.broadcast_arrays(*arrays, **kw)¶
Version of numpy.broadcast_arrays that works with StructuredArray and JAX arrays.
- lsqfitgp.broadcast_to(x, shape, **kw)¶
Version of numpy.broadcast_to that works with StructuredArray and JAX arrays.