larray.Array

class larray.Array(data, axes=None, title=None, meta=None, dtype=None)[source]

An Array object represents a multidimensional, homogeneous array of fixed-size items with labeled axes.

The function asarray() can be used to convert a NumPy array or Pandas DataFrame into an Array.

Parameters
datascalar, tuple, list or NumPy ndarray

Input data.

axescollection (tuple, list or AxisCollection) of axes (int, str or Axis), optional

Axes.

titlestr, optional

Deprecated. See ‘meta’ below.

metalist of pairs or dict or Metadata, optional

Metadata (title, description, author, creation_date, …) associated with the array. Keys must be strings. Values must be of type string, int, float, date, time or datetime.

dtypetype, optional

Datatype for the array. Defaults to None (inferred from the data).

Warning

Metadata is not kept when actions or methods are applied on an array except for operations modifying the object in-place, such as: pop[age < 10] = 0. Do not add metadata to an array if you know you will apply actions or methods on it before dumping it.

See also

sequence

Create an Array by sequentially applying modifications to the array along axis.

ndtest

Create a test Array with increasing elements.

zeros

Create an Array, each element of which is zero.

ones

Create an Array, each element of which is 1.

full

Create an Array filled with a given value.

empty

Create an Array, 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)))
>>> Array(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
>>> # with metadata
>>> arr = Array(data, axes, meta=Metadata(title='my title', author='John Smith'))

Array creation functions

>>> 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
dataNumPy ndarray

Data.

axesAxisCollection

Axes.

metaMetadata

Return metadata of the array.

__init__(data, axes=None, title=None, meta=None, dtype=None)[source]

Methods

__init__(data[, axes, title, meta, dtype])

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.

allclose(other[, rtol, atol, nans_equal, ...])

Compare this array with another array and returns True if they are element-wise equal within a tolerance.

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])

Add a value to this array along an axis.

apply(transform, *args[, by, axes, dtype, ...])

Apply a transformation function to array elements.

apply_map(mapping[, dtype])

Apply a transformation mapping to array elements.

argmax(**kwargs)

argmin(**kwargs)

argsort(**kwargs)

as_table(**kwargs)

astype(dtype[, order, casting, subok, copy])

Copy of the array, cast to a specified type.

broadcast_with(target[, check_compatible])

Return an array that is (NumPy) broadcastable with target.

clip([minval, maxval, out])

Clip (limit) the values in an array.

combine_axes([axes, sep, wildcard])

Combine several axes into one.

compact([display, name])

Detect and remove "useless" axes (ie axes for which values are constant over the whole axis).

copy()

Return a copy of the array.

cumprod([axis])

Return the cumulative product of array elements.

cumsum([axis])

Return the cumulative sum of array elements along an axis.

describe(*args[, percentiles])

Descriptive summary statistics, excluding NaN values.

describe_by(*args[, percentiles])

Descriptive summary statistics, excluding NaN values, along axes or for groups.

diff([axis, d, n, label])

Compute the n-th order discrete difference along a given axis.

divnot0(other)

Divide this array by other, but return 0.0 where other is 0.

drop([labels])

Return array without some labels or indices along an axis.

drop_labels(**kwargs)

dump(self[, header, wide, value_name, ...])

Dump array as a 2D nested list.

eq(other[, rtol, atol, nans_equal])

Compare this array with another array element-wise and returns an array of booleans.

equals(other[, rtol, atol, nans_equal, ...])

Compare this array with another array and returns True if they have the same axes and elements, False otherwise.

expand([target_axes, out, readonly])

Expand this array to target_axes.

extend(**kwargs)

filter([collapse])

Filter the array along the axes given as keyword arguments.

growth_rate([axis, d, label])

Compute the growth along a given axis.

ignore_labels([axes])

Ignore labels from axes (replace those axes by "wildcard" axes).

indexofmax([axis])

Return indices of the maximum values along a given axis.

indexofmin([axis])

Return indices of the minimum values along a given axis.

indicesofsorted([axis, ascending, kind])

Return the indices that would sort this array.

insert(value[, before, after, pos, axis, label])

Insert value in array along an axis.

isin(test_values[, assume_unique, invert])

Compute whether each element of this array is in test_values.

items([axes, ascending])

Return a (label, value) view of the array along axes.

keys([axes, ascending])

Return a view on the array labels along axes.

labelofmax([axis])

Return labels of the maximum values along a given axis.

labelofmin([axis])

Return labels of the minimum values along a given axis.

labelsofsorted([axis, ascending, kind])

Return 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, ...])

Compute the arithmetic mean.

mean_by(*axes_and_groups[, dtype, out, ...])

Compute the arithmetic mean.

median(*axes_and_groups[, out, skipna, keepaxes])

Compute the arithmetic median.

median_by(*axes_and_groups[, out, skipna, ...])

Compute 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()

Return the indices of the elements that are non-zero.

percent(*axes)

Return an array with values given as percent of the total of all values along given axes.

percentile(q, *axes_and_groups[, out, ...])

Compute the qth percentile of the data along the specified axis.

percentile_by(q, *axes_and_groups[, out, ...])

Compute the qth percentile of the data for the specified axis.

posargmax(**kwargs)

posargmin(**kwargs)

posargsort(**kwargs)

prepend(axis, value[, label])

Add an array before this array along an axis.

prod(*axes_and_groups[, dtype, out, skipna, ...])

Compute the product of array elements along given axes/groups.

prod_by(*axes_and_groups[, dtype, out, ...])

Compute the product of array elements for the given axes/groups.

ptp(*axes_and_groups[, out])

Return the range of values (maximum - minimum).

ratio(*axes)

Return an array with all values divided by the sum of values along given axes.

rationot0(*axes)

Return an Array 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])

Rename 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.

reverse([axes])

Reverse axes of an array.

roll([axis, n])

Roll the cells of the array n-times to the right along axis.

set(value, **kwargs)

Set 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])

Replace the labels of one or several axes of the array.

shift(axis[, n])

Shift the cells of the array n-times to the right along axis.

sort_axes(**kwargs)

sort_axis(**kwargs)

sort_labels([axes, ascending])

Sort labels of axes of the array.

sort_values([key, axis, ascending])

Sort values of the array.

split_axes([axes, sep, names, regex, sort, ...])

Split axes and returns a new array.

split_axis(**kwargs)

std(*axes_and_groups[, dtype, ddof, out, ...])

Compute the sample standard deviation.

std_by(*axes_and_groups[, dtype, ddof, out, ...])

Compute the sample standard deviation.

sum(*axes_and_groups[, dtype, out, skipna, ...])

Compute the sum of array elements along given axes/groups.

sum_by(*axes_and_groups[, dtype, out, ...])

Compute the sum of array elements for the given axes/groups.

to_clipboard(*args, **kwargs)

Send the content of the array to the clipboard.

to_csv(filepath[, sep, na_rep, wide, ...])

Write array to a csv file.

to_excel([filepath, sheet, position, ...])

Write array in the specified sheet of specified excel workbook.

to_frame([fold_last_axis_name, dropna])

Convert an Array into a Pandas DataFrame.

to_hdf(filepath, key)

Write array to a HDF file.

to_series([name, dropna])

Convert an Array into a Pandas Series.

to_stata(filepath_or_buffer, **kwargs)

Write array to a Stata .dta file.

transpose(*args)

Reorder axes.

unique([axes, sort, sep])

Return unique values (optionally along axes).

value_counts()

Count number of occurrences of each unique value in array.

values([axes, ascending])

Return a view on the values of the array along axes.

var(*axes_and_groups[, dtype, ddof, out, ...])

Compute the unbiased variance.

var_by(*axes_and_groups[, dtype, ddof, out, ...])

Compute the unbiased variance.

with_axes(**kwargs)

with_total(*args[, op, label])

Add aggregated values (sum by default) along each axis.

Attributes

data

axes

T

Reorder axes.

df

Convert an Array into a Pandas DataFrame.

dtype

Return the type of the data of the array.

i

Allows selection of a subset using indices of labels.

iflat

Access the array by index as if it was flat (one dimensional) and all its axes were combined.

info

Describe an Array (metadata + shape and labels for each axis).

ipoints

Allows selection of arbitrary items in the array based on their N-dimensional index.

item

memory_used

Return the memory consumed by the array in human readable form.

meta

Return metadata of the array.

nbytes

Return the number of bytes used to store the array in memory.

ndim

Return the number of dimensions of the array.

plot

Plot the data of the array into a graph (window pop-up).

points

Allows selection of arbitrary items in the array based on their N-dimensional label index.

series

Convert an Array into a Pandas Series.

shape

Return the shape of the array as a tuple.

size

Return the number of elements in array.

title