Class: MdArray

MdArray

The MdArray class provides a multi-dimensional array like
abstraction for javascript.

Construct an Ml_ndarray object from it's shape in terms of rows,columns,
and any other dimensions it has.

The parameter to the constructor is a javascript object containing keyword
arguments. Eg.:

{
data: [1, 2, 3, 4],
shape: [2, 2]
}


new MdArray(arrayArgs)

Parameters:
Name Type Description
arrayArgs

An object containing the keyword args for the constructor.

Source:

Methods


<static> arange(args)

Create an MdArray containing a range of numeric values.

Parameters:
Name Type Description
args

An object containing a shape field with an array of dimensions,
an end field, and an optional start and by field.

Source:
Returns:

An MdArray containing the requested range of values.


<static> createFilled(args)

Return an MdArray of containing the requested fill value.

Parameters:
Name Type Description
args

An object containing a shape field with an array of
dimensions, and a fill field.

Source:
Returns:

An MdArray of the requested shape containing the repeated fill value.


<static> extendDims(arrayInst, nDims)

Extend arrayInst to meet the dimensions in nDims.

Parameters:
Name Type Description
arrayInst

An instance of MdArray.

nDims

An array containing the required dims after extension.

Source:
Returns:

A new array that is a copy of arrayInst, but extended to satisfy the
extended dimensions in nDims.


<static> ones(args)

Return an MdArray of ones. Args are the shape of the array.

Parameters:
Name Type Description
args

An object containing a shape field with an array of
dimensions.

Source:
Returns:

An MdArray of the requested shape containing all ones.


<static> zeros(args)

Return an MdArray of zeros. Args are the shape of the array.

Parameters:
Name Type Description
args

An object containing a shape field with an array of
dimensions.

Source:
Returns:

An MdArray of the requested shape containing all zeros.


add(that)

Add that to this, and return a new array containing the result.

Parameters:
Name Type Description
that

The array to be added to this one.

Source:
Returns:

A new MdArray containing the values of that + this.


addOnes()

Add a column of ones as the first column in the MdArray.

NOTE: This only works for 2 dimensional arrays.

Source:
Returns:

A new MdArray with the 0'th column being all 1s.


applyOp(that, opFn, dim)

Apply the function opFn to all pairs of matching elements in this and that.

Parameters:
Name Type Description
that

The other object that is part of this operation.

opFn

The operation to be applied to pairs of elements from this
and that.

dim

The dimension along which to apply opFn. For example, dim=1 to
apply down columns of a 2D array.

Source:
Returns:

A new MdArray containing the results of applying opFn to
this and that.


compatible(that)

Test whether the MdArray that is compatible with this one, so that
element wise operations are able to be applied between this and that.

Parameters:
Name Type Description
that

An MdArray object to have it's dimensions checked against
this.

Source:
Returns:

true => this and that are compatible, false otherwise.


copy(A)

Create a copy of this MdArray, and return it.

Parameters:
Name Type Description
A

new MdArray object that is a copy of this one.

Source:

div(that)

Divide this by that and return a new MdArray containing the result.

Parameters:
Name Type Description
that

The array to divide this by.

Source:
Returns:

A new MdArray containing the values of this / that.


dot(that)

Return the dot product of this and that.

Note: This method only runs for 1 or 2 dimensional MdArrays.

Parameters:
Name Type Description
that

An MdArray to be dotted with this one.

Source:
Returns:

A value if this and that are 1-dimensional arrays, or a m x p
size MdArray where m is the number of rows in this, and p is the
number of columns in that.


extendDims(newDims)

Extend the dimensions of this array to fit the values passed in in
newDims. The extension happens by repeating the last value, row, column
or other dimension, until the MdArray is of the requested size.

Parameters:
Name Type Description
newDims

The new dimensions the returned MdArray is to fill.

Source:
Returns:

This MdArray extended to have the requested dimensions.


findIndex(idx)

Return the required 1-d javascript array index indicated by the supplied
index coordinates.

Parameters:
Name Type Description
idx

An array containing the coordinate of the requested element.

Source:
Returns:

The index into data indicated by the supplied idx parameter.


flatten()

Return the data of this MdArray as a flat array.

Source:
Returns:

A flattened array version of this.


foreach(f)

Apply function f to each element of the MdArray.

Parameters:
Name Type Description
f

A function that can be applied to elements of this.

Source:

get(arguments)

Get the value of the element indexed by the coordinate values in the
arguments.

Parameters:
Name Type Description
arguments

indices - eg. X.get(0,1,2);

Source:
Returns:

The value at the array position specified.


max(dimension)

Return the maximum of the values in this MdArray. If a dimension is
supplied, the max is down the requested dimension.

Parameters:
Name Type Description
dimension

The dimension to find the max along.

Source:
Returns:

A new MdArray containing the max, or if no dimension is supplied
a scalar with the value of max over the entire MdArray.


mean(dimension)

Return the mean of the values in this MdArray. If a dimension is
supplied, the mean is down the requested dimension.

Parameters:
Name Type Description
dimension

The dimension to find the mean along.

Source:
Returns:

A new MdArray containing the mean, or if no dimension is
supplied, a scalar with the value of mean over the entire
MdArray.


min(dimension)

Return the minimum of the values in this MdArray. If a dimension is
supplied, the min is down the requested dimension.

Parameters:
Name Type Description
dimension

The dimension to find the min along.

Source:
Returns:

A new MdArray containing the min, or if no dimension is supplied
a scalar with the value of min over the entire MdArray.


mul(that)

Multiply this by that and return a new MdArray containing the result.

Parameters:
Name Type Description
that

The array to be multiplied with this one.

Source:
Returns:

A new MdArray containing the values of this * that.


newSlice(sliceInfo)

Create and return a new MdArray object containing a copy of a slice of
this array.

The sliceInfo parameter is an array of strings that follow the python
numpy array slice syntax. So for example:

  • "2:5" would be taken to mean take just all the values between 2 and 5,
  • ":" would mean take all possible values for this dimension.
  • ":5" would mean take all values up to 5,
    and so on.
Parameters:
Name Type Description
sliceInfo

An array containing strings of sliceInfo.

Source:
Returns:

A new MdArrayObject appropriately created for the slice.


pow(exp)

Raise the values in this array to power exp.

NOTE: This operation occurs in place.

Parameters:
Name Type Description
exp

The exponent.

Source:

set(val, rest)

Set the value in the array element indexed by the remaining values in
arguments.

Parameters:
Name Type Description
val

The value to be assigned into the array.

rest

A list of indices, eg. X.set(x, 0,1,2);

Source:

slice(sliceInfo)

Create and return an ArrayView object representing a slice of this
array.

The sliceInfo parameter is an array of strings that follow the python
numpy array slice syntax. So for example:

  • "2:5" would be taken to mean take just all the values between 2 and 5,
  • ":" would mean take all possible values for this dimension.
  • ":5" would mean take all values up to 5,
    and so on.
Parameters:
Name Type Description
sliceInfo

An array containing strings of sliceInfo.

Source:
Returns:

A new ArrayView object appropriately created for the slice.


std(dimension)

Return the standard deviation of the values in this MdArray. If a
dimension is supplied, the standard deviation is calculated down the
requested dimension.

Parameters:
Name Type Description
dimension

The dimension to find the standard deviation along.

Source:
Returns:

A new MdArray containing the std dev, or if no dimension is
supplied, a scalar with the value of std dev over the entire
MdArray.


sub(that)

Subtract that from this, and return a new MdArray containing the result.

Parameters:
Name Type Description
that

The array to be subtracted from this one.

Source:
Returns:

A new MdArray containing the values of this - that.


sum(dimension)

Return the sum of the values in this MdArray. If a dimension is supplied,
the sum occurs down the requested dimension.

Parameters:
Name Type Description
dimension

The dimension to sum along.

Source:
Returns:

A new MdArray containing the sum, or if no dimension is
supplied, a scalar value set to the sum over the entire
MdArray.


T(args)

Return a new array containing the transpose of this array or, if inPlace
is true, modify this array to be Transposed.

Parameters:
Name Type Description
args

An optional object containing a boolean valued key inPlace.

Source:
Returns:

A new array, or this.


toString()

Return a string representation of the the multi-Dimensional array.

Source:
Returns:

A readable string for the array.