eelbrain.NDVar

class eelbrain.NDVar(x, dims, name=None, info=None)

Container for n-dimensional data.

Parameters
  • x (array_like) – The data.

  • dims (Sequence of Dimension) – The dimensions characterizing the axes of the data. If present, Case should always occupy the first position.

  • name (str) – Name for the NDVar.

  • info (dict) – A dictionary with data properties (can contain arbitrary information that will be accessible in the info attribute).

Notes

An NDVar consists of the following components:

  • A numpy.ndarray, stored in the x attribute.

  • Meta-information describing each axis of the array using a Dimension object (for example, UTS for uniform time series, or Sensor for a sensor array). These dimensions are stored in the dims attribute, with the ith element of dims describing the ith axis of x.

  • A dictionary containing other meta-information stored in the info attribute.

  • A name stored in the name attribute.

NDVar objects support the native abs() and round() functions.

Indexing: For classical indexing, indexes need to be provided in the correct sequence. For example, assuming ndvar’s first axis is time, ndvar[0.1] retrieves a slice at time = 0.1 s. If time is the second axis, the same can be achieved with ndvar[:, 0.1]. In NDVar.sub(), dimensions can be specified as keywords, for example, ndvar.sub(time=0.1), regardless of which axis represents the time dimension.

Shallow copies: When generating a derived NDVars, x and dims are generated without copying data whenever possible. A shallow copy of info is stored. This means that modifying a derived NDVar in place can affect the NDVar it was derived from. When indexing an NDVar, the new NDVar will contain a view on the data whenever possible based on the underlying array (See NumPy Indexing). This only matters when explicitly modifying an NDVar in place (e.g., ndvar += 1) because NDVar methods that return NDVars never implicitly modify the original NDVars in place (see this note).

Examples

Methods

abs([name])

Compute the absolute values

aggregate([x, func, name])

Summarize data in each cell of x

all([axis])

Whether all values are nonzero over given dimensions

any([axis])

Compute presence of any value other than zero over given dimensions

argmax([axis, name])

Find the index of the largest value

argmin([axis, name])

Find the index of the smallest value

assert_dims(dims)

astype(dtype)

Copy of the NDVar with data cast to the specified type

bin([step, start, stop, func, dim, name, ...])

Bin the data along a given dimension (default 'time')

clip([min, max, name, out])

Clip data (see numpy.clip())

copy([name])

A deep copy of the NDVar's data

diff([dim, n, pad, name])

Discrete difference

dot(ndvar[, dims, name])

Dot product

envelope([dim, name])

Compute the Hilbert envelope of a signal

extrema([axis])

Extrema (value farthest away from 0) over given dimensions

fft([dim, name])

Fast fourier transform

flatnonzero()

Return indices where a 1-d NDVar is non-zero

get_axis(name)

Return the data axis for a given dimension name

get_data([dims, mask])

Retrieve the NDVar's data with a specific axes order.

get_dim(name)

Return the Dimension object named name

get_dimnames([names, first, last])

Fill in a partially specified tuple of Dimension names

get_dims([names, first, last])

Return a tuple with the requested Dimension objects

get_mask([name])

Retriev the mask as NDVar

has_dim(name)

label_clusters([threshold, tail, name])

Find and label clusters of values exceeding a threshold

log([base, name])

Element-wise log

mask(mask[, name, missing])

Create a masked version of this NDVar (see numpy.ma.MaskedArray)

max([axis])

Compute the maximum over given dimensions

mean([axis])

Compute the mean over given dimensions

min([axis])

Compute the minimum over given dimensions

nonzero()

Return indices where the NDVar is non-zero

norm(dim[, ord, name])

Norm over dim

ols(x[, name])

Sample-wise ordinary least squares regressions

ols_t(x[, name])

Compute T-values for sample-wise ordinary least squares regressions

quantile([q, axis, interpolation])

The value such that q of the NDVar's values are lower

rename_dim(dim, to[, name])

Rename one of the dimensions

repeat(repeats[, name])

Repeat slices of the NDVar along the case dimension

residuals(x[, name])

The residuals of sample-wise ordinary least squares regressions

rms([axis])

Compute the root mean square over given dimensions

sign([name])

Element-wise indication of the sign

smooth(dim[, window_size, window, mode, ...])

Smooth data by convolving it with a window

std([axis, ddof])

Compute the standard deviation over given dimensions

sub(*args, **kwargs)

Retrieve a slice through the NDVar.

sum([axis])

Compute the sum over given dimensions

summary(*dims, **regions)

Aggregate specified dimensions.

threshold(v[, tail, name])

Set all values below a threshold to 0.

unmask([masked, name])

Remove mask from a masked NDVar

var([axis, ddof])

Compute the variance over given dimensions

zeros(dims[, name, info, dtype])

A new NDVar initialized with 0