OpenSesame
Rapunzel Code Editor
DataMatrix
Support forum
Python Tutorials
MindProbe
Python videos

datamatrix.multidimensional

This module is typically imported as mdim for brevity:

from datamatrix import multidimensional as mdim

What are multidimensional columns?

A MultiDimensionalColumn is a column that itself has a shape; that is, each cell is itself an array. This allows you to represent multidimensional data, such as images and time series.

function flatten(dm)

Flattens all multidimensional columns of a datamatrix to float columns. The result is a new datamatrix where each row of the original datamatrix is repeated for each value of the multidimensional column. The new datamatrix does not contain any multidimensional columns.

This function requires that all multidimensional columns in dm have the same shape, or that dm doesn't contain any multidimensional columns, in which case a copy of dm is returned.

Version note: Moved to datamatrix.multidimensional in 1.0.0

Version note: New in 0.15.0

Example:

from datamatrix import DataMatrix, MultiDimensionalColumn,              multidimensional as mdim

dm = DataMatrix(length=2)
dm.col = 'a', 'b'
dm.m1 = MultiDimensionalColumn(shape=(3,))
dm.m1[:] = 1,2,3
dm.m2 = MultiDimensionalColumn(shape=(3,))
dm.m2[:] = 3,2,1
flat_dm = mdim.flatten(dm)
print('Original:')
print(dm)
print('Flattened:')
print(flat_dm)

Output:

Original:
+---+-----+------------+------------+
| # | col |     m1     |     m2     |
+---+-----+------------+------------+
| 0 |  a  | [1. 2. 3.] | [3. 2. 1.] |
| 1 |  b  | [1. 2. 3.] | [3. 2. 1.] |
+---+-----+------------+------------+
Flattened:
+---+-----+-----+-----+
| # | col |  m1 |  m2 |
+---+-----+-----+-----+
| 0 |  a  | 1.0 | 3.0 |
| 1 |  a  | 2.0 | 2.0 |
| 2 |  a  | 3.0 | 1.0 |
| 3 |  b  | 1.0 | 3.0 |
| 4 |  b  | 2.0 | 2.0 |
| 5 |  b  | 3.0 | 1.0 |
+---+-----+-----+-----+

Arguments:

  • dm -- A DataMatrix
    • Type: DataMatrix

Returns:

A 'flattened' DataMatrix without multidimensional columns

  • Type: DataMatrix

function infcount(col)

Counts the number of INF values for each cell in a multidimensional column, and returns this as an int column.

Version note: Moved to datamatrix.multidimensional in 1.0.0

Version note: New in 0.15.0

Example:

from datamatrix import DataMatrix, MultiDimensionalColumn,              multidimensional as mdim, INF

dm = DataMatrix(length=3)
dm.m = MultiDimensionalColumn(shape=(3,))
dm.m[0] = 1, 2, 3
dm.m[1] = 1, 2, INF
dm.m[2] = INF, INF, INF
dm.nr_of_inf = mdim.infcount(dm.m)
print(dm)

Output:

+---+---------------+-----------+
| # |       m       | nr_of_inf |
+---+---------------+-----------+
| 0 |   [1. 2. 3.]  |    0.0    |
| 1 | [ 1.  2. inf] |    1.0    |
| 2 | [inf inf inf] |    3.0    |
+---+---------------+-----------+

Arguments:

  • col -- A multidimensional column to count the INF values in.
    • Type: MultiDimensionalColumn

Returns:

An int column with the number of INF values in each cell.

  • Type: IntColumn

function nancount(col)

Counts the number of NAN values for each cell in a multidimensional column, and returns this as an int column.

Version note: Moved to datamatrix.multidimensional in 1.0.0

Version note: New in 0.15.0

Example:

from datamatrix import DataMatrix, MultiDimensionalColumn,              multidimensional as mdim, NAN

dm = DataMatrix(length=3)
dm.m = MultiDimensionalColumn(shape=(3,))
dm.m[0] = 1, 2, 3
dm.m[1] = 1, 2, NAN
dm.m[2] = NAN, NAN, NAN
dm.nr_of_nan = mdim.nancount(dm.m)
print(dm)

Output:

+---+---------------+-----------+
| # |       m       | nr_of_nan |
+---+---------------+-----------+
| 0 |   [1. 2. 3.]  |    0.0    |
| 1 | [ 1.  2. nan] |    1.0    |
| 2 | [nan nan nan] |    3.0    |
+---+---------------+-----------+

Arguments:

  • col -- A column to count the NAN values in.
    • Type: MultiDimensionalColumn

Returns:

An int column with the number of NAN values in each cell.

  • Type: IntColumn

function reduce(col, operation=)

Transforms multidimensional values to single values by applying an operation (typically a mean) to each multidimensional value.

Version note: Moved to datamatrix.multidimensional in 1.0.0

Version note: As of 0.11.0, the function has been renamed to reduce(). The original reduce_() is deprecated.

Example:

import numpy as np
from datamatrix import DataMatrix, MultiDimensionalColumn,              multidimensional as mdim

dm = DataMatrix(length=5)
dm.m = MultiDimensionalColumn(shape=(3, 3))
dm.m = np.random.random((5, 3, 3))
dm.mean_y = mdim.reduce(dm.m)
print(dm)

Output:

+---+--------------------------+--------------------+
| # |            m             |       mean_y       |
+---+--------------------------+--------------------+
| 0 | [[0.6437 0.6251 0.9966]  | 0.506500814684164  |
|   |  [0.2201 0.3834 0.7429]  |                    |
|   |  [0.1897 0.6291 0.1278]] |                    |
| 1 | [[0.7567 0.4726 0.9752]  | 0.511178410325664  |
|   |  [0.9967 0.6718 0.1959]  |                    |
|   |  [0.1056 0.2378 0.1884]] |                    |
| 2 | [[0.5837 0.8529 0.8442]  | 0.5400050274244209 |
|   |  [0.0346 0.0271 0.5831]  |                    |
|   |  [0.6003 0.5394 0.7948]] |                    |
| 3 | [[0.0315 0.6281 0.316 ]  | 0.6158464347833806 |
|   |  [0.9574 0.8839 0.3351]  |                    |
|   |  [0.9767 0.8348 0.5792]] |                    |
| 4 | [[0.1213 0.1431 0.6341]  | 0.625507066719668  |
|   |  [0.9593 0.9588 0.8575]  |                    |
|   |  [0.8646 0.5174 0.5733]] |                    |
+---+--------------------------+--------------------+

Arguments:

  • col -- The column to reduce.
    • Type: MultiDimensionalColumn

Keywords:

  • operation -- The operation function to use for the reduction. This function should accept col as first argument, and axis=1 as keyword argument.
    • Default:

Returns:

A reduction of the signal.

  • Type: FloatColumn