larray.LArray¶
-
class
larray.LArray(data, axes=None, title='')[source]¶ A LArray object represents a multidimensional, homogeneous array of fixed-size items with labeled axes.
The function
aslarray()can be used to convert a NumPy array or Pandas DataFrame into a LArray.Parameters: data : scalar, tuple, list or NumPy ndarray
Input data.
axes : collection (tuple, list or AxisCollection) of axes (int, str or Axis), optional
Axes.
title : str, optional
Title of array.
See also
sequence- Create a LArray by sequentially applying modifications to the array along axis.
ndrange- Create a LArray with increasing elements.
zeros- Create a LArray, each element of which is zero.
ones- Create a LArray, each element of which is 1.
full- Create a LArray filled with a given value.
empty- Create a LArray, but leave its allocated memory unchanged (i.e., it contains “garbage”).
Examples
>>> age = Axis([10, 11, 12], 'age') >>> sex = Axis('sex=M,F') >>> time = Axis([2007, 2008, 2009], 'time') >>> axes = [age, sex, time] >>> data = np.zeros((len(axes), len(sex), len(time))) >>> LArray(data, axes) age sex\time 2007 2008 2009 10 M 0.0 0.0 0.0 10 F 0.0 0.0 0.0 11 M 0.0 0.0 0.0 11 F 0.0 0.0 0.0 12 M 0.0 0.0 0.0 12 F 0.0 0.0 0.0 >>> full(axes, 10.0) age sex\time 2007 2008 2009 10 M 10.0 10.0 10.0 10 F 10.0 10.0 10.0 11 M 10.0 10.0 10.0 11 F 10.0 10.0 10.0 12 M 10.0 10.0 10.0 12 F 10.0 10.0 10.0 >>> arr = empty(axes) >>> arr['F'] = 1.0 >>> arr['M'] = -1.0 >>> arr age sex\time 2007 2008 2009 10 M -1.0 -1.0 -1.0 10 F 1.0 1.0 1.0 11 M -1.0 -1.0 -1.0 11 F 1.0 1.0 1.0 12 M -1.0 -1.0 -1.0 12 F 1.0 1.0 1.0 >>> bysex = sequence(sex, initial=-1, inc=2) >>> bysex sex M F -1 1 >>> sequence(age, initial=10, inc=bysex) sex\age 10 11 12 M 10 9 8 F 10 11 12
Attributes
data (NumPy ndarray) Data. axes (AxisCollection) Axes. title (str) Title. Methods
__init__(data[, axes, title])align(other[, join, fill_value, axes])Align two arrays on their axes with the specified join method. all(*axes_and_groups[, out, skipna, keepaxes])Test whether all selected elements evaluate to True. all_by(*axes_and_groups[, out, skipna, keepaxes])Test whether all selected elements evaluate to True. any(*axes_and_groups[, out, skipna, keepaxes])Test whether any selected elements evaluate to True. any_by(*axes_and_groups[, out, skipna, keepaxes])Test whether any selected elements evaluate to True. append(axis, value[, label])Adds an array to self along an axis. argmax(*args, **kwargs)argmin(*args, **kwargs)argsort(*args, **kwargs)as_table([maxlines, edgeitems, light])Generator. astype(dtype[, order, casting, subok, copy])Copy of the array, cast to a specified type. broadcast_with(target)Returns an array that is (NumPy) broadcastable with target. clip(a_min, a_max[, out])Clip (limit) the values in an array. combine_axes([axes, sep, wildcard])Combine several axes into one. compact()Detects and removes “useless” axes (ie axes for which values are constant over the whole axis) copy()Returns a copy of the array. cumprod([axis])Returns the cumulative product of array elements. cumsum([axis])Returns the cumulative sum of array elements along an axis. describe(*args, **kwargs)Descriptive summary statistics, excluding NaN values. describe_by(*args, **kwargs)Descriptive summary statistics, excluding NaN values, along axes or for groups. diff([axis, d, n, label])Calculates the n-th order discrete difference along a given axis. divnot0(other)Divides array by other, but returns 0.0 where other is 0. drop_labels([axes])Drops the labels from axes (replace those axes by “wildcard” axes). dump([header])Dump array as a 2D nested list expand([target_axes, out, readonly])Expands array to target_axes. extend(axis, other)Adds an array to self along an axis. filter([collapse])Filters the array along the axes given as keyword arguments. growth_rate([axis, d, label])Calculates the growth along a given axis. indexofmax([axis])Returns indices of the maximum values along a given axis. indexofmin([axis])Returns indices of the minimum values along a given axis. indicesofsorted([axis, ascending, kind])Returns the indices that would sort this array. insert(value[, before, after, pos, axis, label])Inserts value in array along an axis. labelofmax([axis])Returns labels of the maximum values along a given axis. labelofmin([axis])Returns labels of the minimum values along a given axis. labelsofsorted([axis, ascending, kind])Returns the labels that would sort this array. max(*axes_and_groups[, out, skipna, keepaxes])Get maximum of array elements along given axes/groups. max_by(*axes_and_groups[, out, skipna, keepaxes])Get maximum of array elements for the given axes/groups. mean(*axes_and_groups[, dtype, out, skipna, …])Computes the arithmetic mean. mean_by(*axes_and_groups[, dtype, out, …])Computes the arithmetic mean. median(*axes_and_groups[, out, skipna, keepaxes])Computes the arithmetic median. median_by(*axes_and_groups[, out, skipna, …])Computes the arithmetic median. min(*axes_and_groups[, out, skipna, keepaxes])Get minimum of array elements along given axes/groups. min_by(*axes_and_groups[, out, skipna, keepaxes])Get minimum of array elements for the given axes/groups. nonzero()Returns the indices of the elements that are non-zero. percent(*axes)Returns an array with values given as percent of the total of all values along given axes. percentile(q, *axes_and_groups[, out, …])Computes the qth percentile of the data along the specified axis. percentile_by(q, *axes_and_groups[, out, …])Computes the qth percentile of the data for the specified axis. posargmax(*args, **kwargs)posargmin(*args, **kwargs)posargsort(*args, **kwargs)prepend(axis, value[, label])Adds an array before self along an axis. prod(*axes_and_groups[, dtype, out, skipna, …])Computes the product of array elements along given axes/groups. prod_by(*axes_and_groups[, dtype, out, …])Computes the product of array elements for the given axes/groups. ptp(*axes_and_groups[, out])Returns the range of values (maximum - minimum). ratio(*axes)Returns an array with all values divided by the sum of values along given axes. rationot0(*axes)Returns a LArray with values array / array.sum(axes) where the sum is not 0, 0 otherwise. reindex([axes_to_reindex, new_axis, …])Reorder and/or add new labels in axes. rename([renames, to, inplace])Renames axes of the array. reshape(target_axes)Given a list of new axes, changes the shape of the array. reshape_like(target)Same as reshape but with an array as input. set(value, **kwargs)Sets a subset of array to value. set_axes([axes_to_replace, new_axis, inplace])Replace one, several or all axes of the array. set_labels([axis, labels, inplace])Replaces the labels of an axis of array. shift(axis[, n])Shifts the cells of the array n-times to the left along axis. sort_axes([axes, ascending])Sorts axes of the array. sort_axis(*args, **kwargs)sort_values([key, axis, ascending])Sorts values of the array. split_axes([axes, sep, names, regex, sort, …])Split axes and returns a new array split_axis(*args, **kwargs)std(*axes_and_groups[, dtype, ddof, out, …])Computes the sample standard deviation. std_by(*axes_and_groups[, dtype, ddof, out, …])Computes the sample standard deviation. sum(*axes_and_groups[, dtype, out, skipna, …])Computes the sum of array elements along given axes/groups. sum_by(*axes_and_groups[, dtype, out, …])Computes the sum of array elements for the given axes/groups. to_clipboard(*args, **kwargs)Sends the content of the array to clipboard. to_csv(filepath[, sep, na_rep, transpose, …])Writes array to a csv file. to_excel([filepath, sheet_name, position, …])Writes array in the specified sheet of specified excel workbook. to_frame([fold_last_axis_name, dropna])Converts LArray into Pandas DataFrame. to_hdf(filepath, key, *args, **kwargs)Writes array to a HDF file. to_series([dropna])Converts LArray into Pandas Series. transpose(*args)Reorder axes. var(*axes_and_groups[, dtype, ddof, out, …])Computes the unbiased variance. var_by(*axes_and_groups[, dtype, ddof, out, …])Computes the unbiased variance. with_axes(*args, **kwargs)with_total(*args[, op, label])Add aggregated values (sum by default) along each axis.