hbutils.collection.dimension

Overview:

Dimension operations.

cube_shape

hbutils.collection.dimension.cube_shape(c)[source]
Overview:

Get the shape of cube array. When it is not a cube, raise ValueError.

Arguments:
  • c: The given cube.

Returns:
  • shape: Shape of the cube.

Examples::
>>> import numpy
>>> from hbutils.collection import cube_shape
>>> a = numpy.random.randint(-5, 15, (3, 5, 7, 9)).tolist()
>>> cube_shape(a)
(3, 5, 7, 9)

dimension_switch

hbutils.collection.dimension.dimension_switch(c, dimensions)[source]
Overview:

Switch the dimensions of the cube array.

Arguments:
  • c: Multiple dimensioned array.

  • dimensions: New order of dimensions, should be a tuple of 0 - N-1.

Returns:
  • switched: Switched array.

Examples::
>>> import numpy
>>> from hbutils.collection import cube_shape, dimension_switch
>>> a = numpy.random.randint(-5, 15, (3, 5, 7, 9)).tolist()
>>> cube_shape(a)
(3, 5, 7, 9)
>>> b = dimension_switch(a, (3, 0, 2, 1))
>>> cube_shape(b)
(9, 3, 7, 5)

swap_2d

hbutils.collection.dimension.swap_2d(c)[source]
Overview:

Swap 2d array’s dimension.

Arguments:
  • c: 2d array.

Returns:
  • swapped: Swapped array.

Examples::
>>> from hbutils.collection import swap_2d
>>> swap_2d([
...     [9, 6, 4, 11, 5, -2, 1],
...     [0, 0, 11, 5, 8, -4, 9],
...     [0, 2, 13, 7, 0, 13, 0]
... ])
[[9, 0, 0],
 [6, 0, 2],
 [4, 11, 13],
 [11, 5, 7],
 [5, 8, 0],
 [-2, -4, 13],
 [1, 9, 0]]