Skip to content

Documentation

Rue Yokaze edited this page Jul 1, 2017 · 1 revision

Module-Level APIs

Name Description
make create array of specified shape and type

Array APIs

Name Description
num_dimensions number of dimensions
num_elements total number of elements
element element type
shape array size
reset clear values
get copy of array in numpy.ndarray
set reset array with numpy.ndarray
__getitem__ get array element via index operator
__setitem__ set array element via index operator

Module-Level APIs

make

allocates a boost::multi_array of specified shape and data type.

[array_type] multi_array.make(shape, dtype)

Example

>>> import multi_array
>>> x = multi_array.make([2, 3], multi_array.float32)
>>> x
<multi_array.shared_float_matrix object at 0x105f570c8>

Array APIs

num_dimensions

returns the number of dimensions of the array.

int x.num_dimensions()

Example

>>> x = multi_array.make([2, 2, 2], multi_array.float32)
>>> x.num_dimensions()
3

num_elements

returns the total number of elements of the array.

int x.num_elements()

Example

>>> x = multi_array.make([1, 2, 3, 4], multi_array.float32)
>>> x.num_elements()
24

element

returns the data type of the array.

possible values are bool8, uint8, uint16, uint32, uint64, int8, int16, int32, int64, float32, float64, all defined in numpy.

dtype x.element()

Example

>>> x = multi_array.make([3, 3], multi_array.int32)
>>> x.element()
dtype('int32')

shape

returns the shape of the array.

tuple x.shape()

Example

>>> x = multi_array.make([2, 3, 4], multi_array.float32)
>>> x.shape()
(2, 3, 4)

reset

clears all the element values of the array with zero.

x.reset()

Example

>>> x = multi_array.make([2, 2], multi_array.float32)
>>> x.set(numpy.random.rand(2, 2))
>>> x.get()
array([[ 0.97381461,  0.22102854],
       [ 0.87702358,  0.76791102]], dtype=float32)
>>> x.reset()
>>> x.get()
array([[ 0.,  0.],
       [ 0.,  0.]], dtype=float32)

get

returns a copy of the array stored in numpy.ndarray.

numpy.ndarray x.get()

Example

>>> x = multi_array.make(4, multi_array.float32)
>>> x[1] = 10
>>> x.get()
array([  0.,  10.,   0.,   0.], dtype=float32)

set

resets the array with values from a numpy.ndarray.

x.set(numpy.ndarray nd)

Example

>>> x = multi_array.make([2, 2], multi_array.float32)
>>> x.set(numpy.array([[1, 2], [3, 4]]))
>>> x.get()
array([[ 1.,  2.],
       [ 3.,  4.]], dtype=float32)

__getitem__

returns the value at the supplied index.

[numeric_type] x[index]

Example

>>> x = multi_array.make(4, multi_array.float32)
>>> x[1] = 10
>>> x[1]
10.0

__setitem__

resets the value at the index.

x[index] = [numeric_type]

Example

>>> x = multi_array.make(4, multi_array.float32)
>>> x[1] = 10
>>> x.get()
array([  0.,  10.,   0.,   0.], dtype=float32)