spectrochempy.fromfunction
- fromfunction(cls, function, shape=None, dtype=float, units=None, coordset=None, **kwargs)[source]
- Construct a nddataset by executing a function over each coordinate. - The resulting array therefore has a value - fn(x, y, z)at coordinate- (x, y, z).- Parameters:
- function (callable) – The function is called with N parameters, where N is the rank of - shapeor from the provided- CoordSet.
- shape ((N,) tuple of ints, optional) – Shape of the output array, which also determines the shape of the coordinate arrays passed to - function. It is optional only if- CoordSetis None.
- dtype (data-type, optional) – Data-type of the coordinate arrays passed to - function. By default,- dtypeis float.
- units (str, optional) – Dataset units. When None, units will be determined from the function results. 
- coordset ( - CoordSetinstance, optional) – If provided, this determine the shape and coordinates of each dimension of the returned- NDDataset. If shape is also passed it will be ignored.
- **kwargs – Other kwargs are passed to the final object constructor. 
 
- Returns:
- fromfunction – The result of the call to - functionis passed back directly. Therefore the shape of- fromfunctionis completely determined by- function.
 - See also - fromiter
- Make a dataset from an iterable. 
 - Examples - Create a 1D NDDataset from a function - >>> func1 = lambda t, v: v * t >>> time = scp.Coord.arange(0, 60, 10, units='min') >>> d = scp.fromfunction(func1, v=scp.Quantity(134, 'km/hour'), coordset=scp.CoordSet(t=time)) >>> d.dims ['t'] >>> d NDDataset: [float64] km (size: 6)