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.6618 0.6998 0.0741]  |  0.5443547725483162 |
|   |  [0.2472 0.3113 0.7908]  |                     |
|   |  [0.5528 0.6253 0.9361]] |                     |
| 1 | [[0.6652 0.3922 0.8917]  |  0.5481244425562843 |
|   |  [0.1525 0.462  0.8074]  |                     |
|   |  [0.6837 0.5212 0.3571]] |                     |
| 2 | [[0.7294 0.4912 0.2583]  |  0.4062452227753534 |
|   |  [0.275  0.8228 0.063 ]  |                     |
|   |  [0.4764 0.3392 0.2007]] |                     |
| 3 | [[0.4418 0.9328 0.4324]  | 0.46956475598509695 |
|   |  [0.0455 0.1345 0.588 ]  |                     |
|   |  [0.3549 0.7078 0.5884]] |                     |
| 4 | [[0.8168 0.913  0.7273]  |  0.5763400860122321 |
|   |  [0.3866 0.7422 0.2323]  |                     |
|   |  [0.0632 0.5797 0.7259]] |                     |
+---+--------------------------+---------------------+

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