numeric v0.0.1 Elyanah.Numeric.Array

Array operations on Elixir Lists.

Summary

Functions

Elementwise addition of a and b. If a and b are both lists, follows the same rules for dims as Elyanah.Numeric.Array.zip/3 Otherwise, will convert the non-list into a list of the same size as the list

Elementwise division of a and b. If a and b are both lists, follows the same rules for dims as Elyanah.Numeric.Array.zip/3 Otherwise, will convert the non-list into a list of the same size as the list

Calculate the dot product of two lists. Follows the same rules for dims as Elyanah.Numeric.Array.zip/3

Elementwise multiplication of a and b. If a and b are both lists, follows the same rules for dims as Elyanah.Numeric.Array.zip/3 Otherwise, will convert the non-list into a list of the same size as the list

Elementwise subtraction of b from a. If a and b are both lists, follows the same rules for dims as Elyanah.Numeric.Array.zip/3 Otherwise, will convert the non-list into a list of the same size as the list

Zip two lists together, returning a Stream. If dims == :strict will raise an error for unequally-sized lists. If dims == :cycle will cycle the smaller list (like NumPy). If dims == :trunc will truncate the longer list

Functions

add(a, b, dims \\ :trunc)

Elementwise addition of a and b. If a and b are both lists, follows the same rules for dims as Elyanah.Numeric.Array.zip/3 Otherwise, will convert the non-list into a list of the same size as the list.

Examples

iex> Elyanah.Numeric.Array.add([1,2,3], 3)
[4, 5, 6]
iex> Elyanah.Numeric.Array.add(3, [1,2,3])
[4, 5, 6]
iex> Elyanah.Numeric.Array.add([1,2,3], [4,5,6])
[5, 7, 9]
iex> Elyanah.Numeric.Array.add([1,2,3], [4,5])
[5, 7]
iex> Elyanah.Numeric.Array.add([1,2,3], [4,5], :cycle)
[5, 7, 7]
iex> Elyanah.Numeric.Array.add([1,2,3], [4,5], :strict)
** (ArithmeticError) bad argument in arithmetic expression
divide(a, b, dims \\ :trunc)

Elementwise division of a and b. If a and b are both lists, follows the same rules for dims as Elyanah.Numeric.Array.zip/3 Otherwise, will convert the non-list into a list of the same size as the list.

Examples

iex> Elyanah.Numeric.Array.divide([1,2,3], 3)
[0.3333333333333333, 0.6666666666666666, 1.0]
iex> Elyanah.Numeric.Array.divide(3, [1,2,3])
[3.0, 1.5, 1.0]
iex> Elyanah.Numeric.Array.divide([1,2,3], [4,5,6])
[0.25, 0.4, 0.5]
iex> Elyanah.Numeric.Array.divide([1,2,3], [4,5])
[0.25, 0.4]
iex> Elyanah.Numeric.Array.divide([1,2,3], [4,5], :cycle)
[0.25, 0.4, 0.75]
iex> Elyanah.Numeric.Array.divide([1,2,3], [4,5], :strict)
** (ArithmeticError) bad argument in arithmetic expression
dot(a, b, dims \\ :trunc)

Calculate the dot product of two lists. Follows the same rules for dims as Elyanah.Numeric.Array.zip/3

Examples

iex> Elyanah.Numeric.Array.dot([1,2,3], [4,5,6])
32
iex> Elyanah.Numeric.Array.dot([1,2,3], [4,5])
14
iex> Elyanah.Numeric.Array.dot([1,2,3], [4,5], :cycle)
26
iex> Elyanah.Numeric.Array.dot([1,2,3], [4,5], :strict)
** (ArithmeticError) bad argument in arithmetic expression
multiply(a, b, dims \\ :trunc)

Elementwise multiplication of a and b. If a and b are both lists, follows the same rules for dims as Elyanah.Numeric.Array.zip/3 Otherwise, will convert the non-list into a list of the same size as the list.

Examples

iex> Elyanah.Numeric.Array.multiply([1,2,3], 3)
[3, 6, 9]
iex> Elyanah.Numeric.Array.multiply(3, [1,2,3])
[3, 6, 9]
iex> Elyanah.Numeric.Array.multiply([1,2,3], [4,5,6])
[4, 10, 18]
iex> Elyanah.Numeric.Array.multiply([1,2,3], [4,5])
[4, 10]
iex> Elyanah.Numeric.Array.multiply([1,2,3], [4,5], :cycle)
[4, 10, 12]
iex> Elyanah.Numeric.Array.multiply([1,2,3], [4,5], :strict)
** (ArithmeticError) bad argument in arithmetic expression
subtract(a, b, dims \\ :trunc)

Elementwise subtraction of b from a. If a and b are both lists, follows the same rules for dims as Elyanah.Numeric.Array.zip/3 Otherwise, will convert the non-list into a list of the same size as the list.

Examples

iex> Elyanah.Numeric.Array.subtract([1,2,3], 3)
[-2, -1, 0]
iex> Elyanah.Numeric.Array.subtract(3, [1,2,3])
[2, 1, 0]
iex> Elyanah.Numeric.Array.subtract([1,2,3], [4,5,6])
[-3, -3, -3]
iex> Elyanah.Numeric.Array.subtract([1,2,3], [4,5])
[-3, -3]
iex> Elyanah.Numeric.Array.subtract([1,2,3], [4,5], :cycle)
[-3, -3, -1]
iex> Elyanah.Numeric.Array.subtract([1,2,3], [4,5], :strict)
** (ArithmeticError) bad argument in arithmetic expression
zip(a, b, dims \\ :trunc)

Zip two lists together, returning a Stream. If dims == :strict will raise an error for unequally-sized lists. If dims == :cycle will cycle the smaller list (like NumPy). If dims == :trunc will truncate the longer list.

Examples

iex> Elyanah.Numeric.Array.zip([1,2,3], [4,5,6]) |> Enum.to_list()
[{1, 4}, {2, 5}, {3, 6}]
iex> Elyanah.Numeric.Array.zip([1,2,3], [4,5]) |> Enum.to_list()
[{1, 4}, {2, 5}]
iex> Elyanah.Numeric.Array.zip([1,2,3], [4,5], :cycle) |> Enum.to_list()
[{1, 4}, {2, 5}, {3, 4}]
iex> Elyanah.Numeric.Array.zip([1,2,3], [4,5], :strict) |> Enum.to_list()
** (ArithmeticError) bad argument in arithmetic expression