NArray Example List (0.7.0.1)
This example list is a work in progress. The methods used here correspond to the 0.7.0.1 NArray package which can be downloaded here and is currently under development. This list is similar to the Numpy Example List.
Returns a copy of the NArray (not simply a reference) with each element's respective absolute value.
Returns: A NArray with each elements absolute value.
Options: None.
###Examples:
=> a = Num::DFloat.new([2,3]).seq(-6)
=> Num::DFloat#shape=[2,3]:
[[-6, -5, -4],
[-3, -2, -1]]
=> a.abs
=> Num::DFloat#shape=[2,3]:
[[6, 5, 4],
[3, 2, 1]]
Returns the byte size of the NArray. Returns 0 for Num::Bit types and 8*(number of elements) for Num::DFloat types.
Returns: The byte size value of the NArray.
Options: None.
###Examples:
>> a = Num::DFloat.new([3,3]).fill(1)
=> Num::DFloat#shape=[3,3]:
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]
>> a.byte_size
=> 72
>> a = Num::Bit.new([3,3,3]).fill(1)
=> Num::Bit#shape=[3,3,3]:
[[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]],
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]],
[[1, 1, 1],
[1, 1, 1],
...
>> a.byte_size
=> 0
Returns the smallest following integer of each element in the NArray.
Returns: A NArray containing the smallest following integer of each element.
Options: None.
###Examples:
>> a = Num::DFloat.new([2,3]).rand
=> Num::DFloat#shape=[2,3]:
[[0.539948, 0.737815, 0.165089],
[0.0508827, 0.108065, 0.0687079]]
>> a[0,1].ceil
=> 1
>> a.ceil
=> Num::DFloat#shape=[2,3]:
[[1, 1, 1],
[1, 1, 1]]
>> a
=> Num::DFloat#shape=[2,3]:
[[0.539948, 0.737815, 0.165089],
[0.0508827, 0.108065, 0.0687079]]
Allows the creation of an Array of multiple types of objects. Objects retain their original format. Syntax: a.coerce(b) creates an array of a and b, regardless of type does not allow for a.b.coerce(c) a.coerce(3) creates an array of a and the number 3 also works with integers Bugs: 'a.b.coerce(c)' won't work, as shown on ruby-doc.org under Class: Numeric Also, 'a.coerce(b)' won't work when 'a' is a Num::Bit, but 'b.coerce(a)' will work.
Returns: An array including the objects coerced together.
Options: None.
###Examples:
>> d = Num::Bit.new([1,2]).store([1,0])
=> [1, 0]
>> b = Num::DFloat.new([1,2]).store([2,2])
=> Num::DFloat#shape=[1,2]:
[[2, 2]]
>> b.coerce(d)
=> [Num::DFloat#shape=[2]:
[1, 0], Num::DFloat#shape=[1,2]:
[[2, 2]]]
>> a.coerce(0)
=> [Num::DFloat#shape=[]:
(scalar)0, Num::DFloat#shape=[1,2]:
[[2, 2]]]
>> blah = a.coerce(0)
=> [Num::DFloat#shape=[]:
(scalar)0, Num::DFloat#shape=[1,2]:
[[2, 2]]]
>> blah[0]
=> Num::DFloat#shape=[]:
(scalar)0
>> blah[1]
=> Num::DFloat#shape=[1,2]:
[[2, 2]]
>> blah[1].is_a?Num::DFloat
=> true
Returns potentially useful data about the NArray(shown below).
Returns: Debug info.
Options: None.
###Examples:
>> d = Num::DFloat.new([3,3]).rand_norm
=> Num::DFloat#shape=[3,3]:
[[0.272395, -0.855477, 0.568161],
[0.233815, -0.212585, -0.398944],
[-0.00360752, 0.18619, -0.540167]]
>> d.debug_info
Num::DFloat:
id = 0x9920078
column_major? = 0
byte_swapped? = 0
inplace? = 0
size = 9
ndim = 2
shape = 0x99e95a8
stride = 0x99e8070
index = 0x0
data = 0x9920028
offset = 0
shape = [ 3 3 ]
stride = [ 24 8 ]
=> nil
Changes each element of the array to the specified value. Works whether the array has elements that are values already or is empty (filled with nil values). The value must be a compatable type with the NArray.
Converts to: A NArray filled with the specified value.
Options: '.fill(number)'.
###Examples:
=> Num::DFloat#shape=[2,2,2](no data)
>> a.fill(3.1415927)
=> Num::DFloat#shape=[2,2,2]:
[[[3.14159, 3.14159],
[3.14159, 3.14159]],
[[3.14159, 3.14159],
[3.14159, 3.14159]]]
>> a
=> Num::DFloat#shape=[2,2,2]:
[[[3.14159, 3.14159],
[3.14159, 3.14159]],
[[3.14159, 3.14159],
[3.14159, 3.14159]]]
Returns a "Bit" NArray which shows whether each element in the NArray is finite or not. '0' = number is not finite. '1' = number is finite.
Returns: A Bit NArray
Options: None.
###Examples:
>> a = Num::DFloat.new([2,3]).seq
=> Num::DFloat#shape=[2,3]:
[[0, 1, 2],
[3, 4, 5]]
>> a.finite?
=> Num::Bit#shape=[2,3]:
[[1, 1, 1],
[1, 1, 1]]
>> a = a/0
=> Num::DFloat#shape=[2,3]:
[[-nan, inf, inf],
[inf, inf, inf]]
>> a.finite?
=> Num::Bit#shape=[2,3]:
[[0, 0, 0],
[0, 0, 0]]
Returns a copy of the Array (not simply a reference) that has been flattened to one dimension.
Returns: A one dimensional NArray.
Options: None.
###Examples:
#no current option for order, as in numpy
>> a = Num::DFloat.new([1,2,3]).seq
=> Num::DFloat#shape=[1,2,3]:
[[[0, 1, 2],
[3, 4, 5]]]
>> a.flatten
=> Num::DFloat#shape=[6]:
[0, 1, 2, 3, 4, 5]
>> a
=> Num::DFloat#shape=[1,2,3]:
[[[0, 1, 2],
[3, 4, 5]]]
>> a.transpose
=> Num::DFloat#shape=[1,3,2]:
[[[0, 3],
[1, 4],
[2, 5]]]
>> a.transpose.flatten
=> Num::DFloat#shape=[6]:
[0, 3, 1, 4, 2, 5]
Returns an array of string elements in a multidimensional format. With options fills the array with specified value(x) 'mod.' the original value(y)(e.g. x % y).
Returns: An array filled with strings of the original values or filled with a specified value.
Options: '.format_to_a(x)' -- x = a value
###Examples:
>> a = Num::DFloat.new([2,2,2]).fill(0)
=> Num::DFloat#shape=[2,2,2]:
[[[0, 0],
[0, 0]],
[[0, 0],
[0, 0]]]
>> a.format_to_a
=> [[["0", "0"], ["0", "0"]], [["0", "0"], ["0", "0"]]]
>> a.format_to_a.is_a?(Array)
=> true
>> a
=> Num::DFloat#shape=[2,2,2]:
[[[0, 0],
[0, 0]],
[[0, 0],
[0, 0]]]
>> a.fill(5)
=> Num::DFloat#shape=[2,2,2]:
[[[5, 5],
[5, 5]],
[[5, 5],
[5, 5]]]
>> a.format_to_a(8)
=> [[[3.0, 3.0], [3.0, 3.0]], [[3.0, 3.0], [3.0, 3.0]]]
>> 8%5
=> 3
Contents ##.floor
Rounds to the next integer down in all instances of the given NArray (Note: Unlike the 'floor()' function in Numpy, '.floor' will return the next integer that is less than the given element, returning a larger negative integer for negative elements in the NArray).
Returns: A NArray of the same type.
Options: None.
>> a = Num::DFloat.new([2,2]).store([[-1.9,2.3],[-3.2,4.9]])
=> Num::DFloat#shape=[2,2]:
[[-1.9, 2.3],
[-3.2, 4.9]]
>> a.floor
=> Num::DFloat#shape=[2,2]:
[[-2, 2],
[-4, 4]]
Returns a "Bit" NArray which shows whether each element in the NArray is infinite or not. '0' = number is not infinite. '1' = number is infinite.
Returns: A BIT NArray.
Options: None.
>> a = Num::DFloat.new([2,3]).seq
=> Num::DFloat#shape=[2,3]:
[[0, 1, 2],
[3, 4, 5]]
>> a.inf?
=> Num::Bit#shape=[2,3]:
[[0, 0, 0],
[0, 0, 0]]
>> a = a/0
=> Num::DFloat#shape=[2,3]:
[[-nan, inf, inf],
[inf, inf, inf]]
>> a.inf?
=> Num::Bit#shape=[2,3]:
[[0, 1, 1],
[1, 1, 1]]
Returns the numerical median of the NArray.
Returns: The median of all elements or A NArray of medians from the specified dimensions.
Options: 'a.median(start_dim)'; 'a.median' will take the median of the entire array.
###Examples:
>> a.seq
=> Num::DFloat#shape=[2,3]:
[[0, 1, 2],
[3, 4, 5]]
>> a.median
=> 2.5
>> a.median(0)
=> Num::DFloat#shape=[3]:
[1.5, 2.5, 3.5]
>> a.median(1)
=> Num::DFloat#shape=[2]:
[1, 4]
Returns a copy of the NArray with each element multiplied by -1. Does not save the results of .minus to the array that it performed the operation upon.
Returns: A NArray of the same type.
Options: None.
=> a = (a.rand_norm*100).round
=> Num::DFloat#shape=[3,3]:
[[-48, -63, 203],
[84, -60, -99],
[11, 13, -74]]
=> a.minus
=> Num::DFloat#shape=[3,3]:
[[48, 63, -203],
[-84, 60, 99],
[-11, -13, 74]]
Returns the minimum value of the array (if no option is specified) or the minimum column, row, etc when a dimension is specified. Syntax: a.min returns minimum value of the array a.min(start_dim) returns the minimum of the specified dimension
Returns: A NArray of the same type.
Options: 'a.min(start_dim)'.
>> a = Num::DFloat.new([3,3]).seq
=> Num::DFloat#shape=[3,3]:
[[0, 1, 2],
[3, 4, 5],
[6, 7, 8]]
>> a.min
=> 0.0
>> a.min(0)
=> Num::DFloat#shape=[3]:
[0, 1, 2]
>> a.min(1)
=> Num::DFloat#shape=[3]:
[0, 3, 6]
Returns the maximum value of the array (if no option is specified) or the max column, row, etc when a dimension is specified. Syntax: a.max returns the maximum value of the array a.max(start_dim) returns the maximum of the specified dimension
Returns: The max value of all elements or A NArray filled with the maximums for the specified dimension.
Options: 'a.max(start_dim)'.
>> a = Num::DFloat.new([3,3]).seq
=> Num::DFloat#shape=[3,3]:
[[0, 1, 2],
[3, 4, 5],
[6, 7, 8]]
>> a.max
=> 8.0
>> a.max(0)
=> Num::DFloat#shape=[3]:
[6, 7, 8]
>> a.max(1)
=> Num::DFloat#shape=[3]:
[2, 5, 8]
Returns a 'Bit' NArray which shows whether each element in the NArray is 'not a number' (nan) or can be represented. '0' = number is representable. '1' = 'not a number' (nan) or unrepresentable.
Returns: A BIT NArray
Options: None.
>> a = Num::DFloat.new([2,2]).seq
=> Num::DFloat#shape=[2,2]:
[[0, 1],
[2, 3]]
>> a = a/0
=> Num::DFloat#shape=[2,2]:
[[-nan, inf],
[inf, inf]]
>> a.nan?
=> Num::Bit#shape=[2,2]:
[[1, 0],
[0, 0]]
>> a
=> Num::DFloat#shape=[2,2]:
[[-nan, inf],
[inf, inf]]
Returns the numerical integer value of the number of dimensions of the given array.
Returns: An integer value.
Options: None.
>> a = Num::DFloat.new([3,3,3,3,3]).fill(1)
=> Num::DFloat#shape=[3,3,3,3,3]:
...
>> a.ndim
=> 5
Returns the numerical value of the flattened length of the array as an integer, regardless of dimension. Works even if filled with nils (default behavior for an unfilled NArray).
See Also: .size, .total
Return: An integer value.
Options: None.
>> a = Num::DFloat.new([3,3])
=> Num::DFloat#shape=[3,3](no data)
>> a.length
=> 9
>> a.fill(1)
=> Num::DFloat#shape=[3,3]:
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]
>> a.length
=> 9
Stores random numbers ranging from 0 to 1 in each element of the array, erasing its previous contents.
Converts to: A NArray of the same type and shape filled with random values.
Options: None.
=> a = Num::DFloat.new([2,3]).seq(-6)
=> Num::DFloat#shape=[2,3]:
[[-6, -5, -4],
[-3, -2, -1]]
=> a.rand
=> Num::DFloat#shape=[2,3]:
[[0.0617545, 0.373067, 0.794815],
[0.201042, 0.116041, 0.344032]]
Stores random numbers ranging from -1 to 1 in each element of the array, erasing its previous contents.
Converts to: A NArray of the same type and shape filled with random values.
Options: None.
>> a = Num::DFloat.new([2,2]).seq(-3,3)
=> Num::DFloat#shape=[2,2]:
[[-3, 0],
[3, 6]]
>> a.rand_norm
=> Num::DFloat#shape=[2,2]:
[[-0.581255, -0.168354],
[0.586895, -0.595142]]
>> a
=> Num::DFloat#shape=[2,2]:
[[-0.581255, -0.168354],
[0.586895, -0.595142]]
Returns a copy of the array with the numbers rounded to the nearest integer (does not store directly to parent object by default). If negative, it rounds to the nearest integer as well, either up or down.
Returns: A NArray Of same type and shape.
Options: None.
=> a = Num::DFloat.new([2,3]).rand
=> Num::DFloat#shape=[2,3]:
[[0.0617545, 0.373067, 0.794815],
[0.201042, 0.116041, 0.344032]]
=> a.round
=> Num::DFloat#shape=[2,3]:
[[1, 1, 0],
[0, 0, 0]]
=> a = a*-1
=> Num::DFloat#shape=[2,3]:
[[-0.539948, -0.737815, -0.165089],
[-0.0508827, -0.108065, -0.0687079]]
=> a.round
=> Num::DFloat#shape=[2,3]:
[[-1, -1, -0],
[-0, -0, -0]]
Returns the number of dimensions (ranks) of the NArray.
Returns: An integer value.
Options: None.
>> a = Num::DFloat.new([2,2,2])
=> Num::DFloat#shape=[2,2,2](no data)
>> a.rank
=> 3
>> a = Num::DFloat.new([2,2,2,2,2,2,2,2,2,2])
=> Num::DFloat#shape=[2,2,2,2,2,2,2,2,2,2](no data)
>> a.rank
=> 10
>> a = Num::DFloat.new([2])
=> Num::DFloat#shape=[2](no data)
>> a.rank
=> 1
>> a = Num::DFloat.new()
=> Num::DFloat#shape=[](no data)
>> a.rank
=> 0
Retains the number of elements in the NArray, but changes their arrangement to the given dimensions. Must have the same total number of elements as the original NArray. FYI: This method will only return a copy of the NArray with the reshape function performed. Set to a variable to store the result or use 'reshape!' to store the result to the original NArray.
Returns: A NArray of the same type and specified shape.
Options: a.reshape(dim1,dim2,dim3,...)
>> a = Num::DFloat.new([2,2,2]).fill(5)
=> Num::DFloat#shape=[2,2,2]:
[[[5, 5],
[5, 5]],
[[5, 5],
[5, 5]]]
>> a.reshape(4,2)
=> Num::DFloat#shape=[4,2]:
[[5, 5],
[5, 5],
[5, 5],
[5, 5]]
>> a.reshape(2,4)
=> Num::DFloat#shape=[2,4]:
[[5, 5, 5, 5],
[5, 5, 5, 5]]
>> a.reshape(1,8)
=> Num::DFloat#shape=[1,8]:
[[5, 5, 5, 5, 5, 5, 5, 5]]
>> a.reshape(8,1)
=> Num::DFloat#shape=[8,1]:
[[5],
[5],
[5],
[5],
[5],
[5],
[5],
[5]]
Same function as reshape, but stores the result to the originating NArray.
Converts to: A NArray of the same type and specified shape.
Options: a.reshape!(dim1,dim2,dim3,...)
>> a = Num::DFloat.new([2,2,2]).fill(5)
=> Num::DFloat#shape=[2,2,2]:
[[[5, 5],
[5, 5]],
[[5, 5],
[5, 5]]]
>> a.reshape(1,8)
=> Num::DFloat#shape=[1,8]:
[[5, 5, 5, 5, 5, 5, 5, 5]]
>> a
=> Num::DFloat#shape=[2,2,2]:
[[[5, 5],
[5, 5]],
[[5, 5],
[5, 5]]]
>> a.reshape!(1,8)
=> Num::DFloat#shape=[1,8]:
[[5, 5, 5, 5, 5, 5, 5, 5]]
>> a
=> Num::DFloat#shape=[1,8]:
[[5, 5, 5, 5, 5, 5, 5, 5]]
Contents ##.seq
Fills a NArray with a given sequence of numbers.
Converts to: A NArray of same type and shape.
Options: '.seq(startnum, step)' Fills the array with a given starting value, and does so incrementally using the increment value step. '.seq' If no parameters are given, the defaults are used with startnum of 0 and step of 1.
###Examples:
>> a = Num::DFloat.new([5,5]).seq(-1,5)
=> Num::DFloat#shape=[5,5]:
[[-1, 4, 9, 14, 19],
[24, 29, 34, 39, 44],
[49, 54, 59, 64, 69],
[74, 79, 84, 89, 94],
[99, 104, 109, 114, 119]]
>> a = Num::DFloat.new([2,3]).seq
=> Num::DFloat#shape=[2,3]:
[[0, 1, 2],
[3, 4, 5]]
Contents ##.shape Returns the shape (the dimensions-- number of rows, number of columns, and so on) of the NArray as an array object.
Returns: An array of integers.
Options: None.
###Example:
>> a = Num::DFloat.new([2,2,2])
=> Num::DFloat#shape=[2,2,2](no data)
>> a.shape
=> [2, 2, 2]
Contents ##.sort
Returns a sorted NArray.
Returns: A NArray of the same type and shape (even when used with options).
Options: -.sort(x) - sorts the given dimension; -.sort(x,y,z,...) - sorts the given dimensions; -.sort - sorts the entire NArray
###Examples:
>> a
=> Num::DFloat#shape=[3,3]:
[[6, 3, 0],
[4, 2, 7],
[9, 5, 8]]
>> a.sort(0)
=> Num::DFloat#shape=[3,3]: #columns are sorted
[[4, 2, 0],
[6, 3, 7],
[9, 5, 8]]
>> a.sort(1)
=> Num::DFloat#shape=[3,3]: #rows are sorted
[[0, 3, 6],
[2, 4, 7],
[5, 8, 9]]
>> a.sort
=> Num::DFloat#shape=[3,3]: #all elements sorted
[[0, 2, 3],
[4, 5, 6],
[7, 8, 9]]
>> a.sort(0,1)
=> Num::DFloat#shape=[3,3]: #all elements sorted
[[0, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Contents ##.sort!
Same as '.sort' but results are stored in the NArray given and returned.
Converts to: A NArray of the same type and shape (even when used with options).
Options: -.sort!(x) - sorts the given dimension; -.sort!(x,y,z,...) - sorts the given dimensions; -.sort! - sorts the entire NArray
###Examples:
>> a.rand
=> Num::DFloat#shape=[3,3]:
[[0.860828, 0.171934, 0.360198],
[0.151675, 0.490398, 0.995591],
[0.271669, 0.171815, 0.469158]]
>> a.sort!(0)
=> Num::DFloat#shape=[3,3]:
[[0.151675, 0.171815, 0.360198],
[0.271669, 0.171934, 0.469158],
[0.860828, 0.490398, 0.995591]]
>> a.sort!(1)
=> Num::DFloat#shape=[3,3]:
[[0.151675, 0.171815, 0.360198],
[0.171934, 0.271669, 0.469158],
[0.490398, 0.860828, 0.995591]]
>> a
=> Num::DFloat#shape=[3,3]:
[[0.151675, 0.171815, 0.360198],
[0.171934, 0.271669, 0.469158],
[0.490398, 0.860828, 0.995591]]
Contents ##.sort_index
Returns a NArray of type integer where each integer corresponds to an index of the original NArray. The positions of the index values are sorted according to the value they represent.
Returns: A NArray of type integer and same shape.
Options: '.sort_index(start_dim)'
###Examples:
>> a
=> Num::DFloat#shape=[2,3]:
[[5.06175, 5.37307, 5.79482],
[5.20104, 5.11604, 5.34403]]
>> a.sort_index
=> Num::Int32#shape=[2,3]:
[[0, 4, 3],
[5, 1, 2]]
>> a.sort_index(0)
=> Num::Int32#shape=[2,3]:
[[0, 4, 5],
[3, 1, 2]]
>> a.sort_index(1)
=> Num::Int32#shape=[2,3]:
[[0, 1, 2],
[4, 3, 5]]
Contents ##.store_array
Takes an array (or an array of one as a number e.g. "9") and stores it in the first vertical column, and makes all other values 0. Coupled with .transpose can be used to fill a NArray with all the values from the array.
Converts to: A NArray of the same type and shape.
Options: .store_array(c), "c" is the array to be stored.
###Examples:
>> c = [1,2,3,4,5,6,7,8,9,10,11,12]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
>> a = Num::DFloat.new([3,4]).fill(0)
=> Num::DFloat#shape=[3,4]:
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
>> a.store_array(c)
=> Num::DFloat#shape=[3,4]:
[[1, 0, 0, 0],
[2, 0, 0, 0],
[3, 0, 0, 0]]
>> a.transpose.store_array(c)
=> Num::DFloat#shape=[4,3]:
[[1, 5, 9],
[2, 6, 10],
[3, 7, 11],
[4, 8, 12]]
>> a
=> Num::DFloat#shape=[3,4]:
[[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]]
>> a.store_array(9)
=> Num::DFloat#shape=[3,4]:
[[9, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
Contents ##.store()
Stores the given input data into the NArray.
Converts to: A NArray of the same type and shape.
Options: .store(value) Stores the value into each element of the array directly, erasing previous contents (not a soft copy or reference). .store([1,2,3,4,5,...]) Must be the same number of elements as a row in the destination NArray, but will store the row to all rows in the NArray. .store(multidimensional data in brackets) Must match the destination dimensions, but will store all of the data once (if the size of the multidimensional data is the exact size in all dimensions of the array) or will repeatedly store the data until the end of the array (if data matching dimensions of a portion of the array is used).
###Examples:
>> a = Num::DFloat.new([2,2,2])
=> Num::DFloat#shape=[2,2,2](no data)
>> a = Num::DFloat.new([2,2,2,3]).store(1)
=> Num::DFloat#shape=[2,2,2,3]:
[[[[1, 1, 1],
[1, 1, 1]],
[[1, 1, 1],
[1, 1, 1]]],
[[[1, 1, 1],
[1, 1, 1]],
[[1, 1, 1],
[1, 1, 1]]]]
>> a.store([1,2,3]) #one dimensional data
=> Num::DFloat#shape=[2,2,2,3]:
[[[[1, 2, 3],
[1, 2, 3]],
[[1, 2, 3],
[1, 2, 3]]],
[[[1, 2, 3],
[1, 2, 3]],
[[1, 2, 3],
[1, 2, 3]]]]
>> a.store([[2,3,4],[5,6,7]]) #two dimensional data
=> Num::DFloat#shape=[2,2,2,3]:
[[[[2, 3, 4],
[5, 6, 7]],
[[2, 3, 4],
[5, 6, 7]]],
[[[2, 3, 4],
[5, 6, 7]],
[[2, 3, 4],
[5, 6, 7]]]]
a.store([[[1, 5, 6],[2, 3, 4]],[[11, 12, 13],[14, 15, 1117.5]]]) #three dimensional data
=> Num::DFloat#shape=[2,2,2,3]:
[[[[1, 5, 6],
[2, 3, 4]],
[[11, 12, 13],
[14, 15, 1117.5]]],
[[[1, 5, 6],
[2, 3, 4]],
[[11, 12, 13],
[14, 15, 1117.5]]]]
>> a.store([[[[1, 5, 6],[2, 3, 4]],[[11, 12, 13],[14, 15, 1117.5]]],[[[11, 55, 66],[22, 33, 44]],[[111, 122, 133],[144, 155, 11147.56]]]]) #store the entire contents of a NArray, in this case, all 4 dimensions
=> Num::DFloat#shape=[2,2,2,3]:
[[[[1, 5, 6],
[2, 3, 4]],
[[11, 12, 13],
[14, 15, 1117.5]]],
[[[11, 55, 66],
[22, 33, 44]],
[[111, 122, 133],
[144, 155, 11147.6]]]]
>> d = Num::DFloat.new([3,4,5]).seq
=> Num::DFloat#shape=[3,4,5]:
[[[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]],
[[20, 21, 22, 23, 24],
[25, 26, 27, 28, 29],
[30, 31, 32, 33, 34],
[35, 36, 37, 38, 39]],
...
>> d.transpose
=> Num::DFloat#shape=[3,5,4]:
[[[0, 5, 10, 15],
[1, 6, 11, 16],
[2, 7, 12, 17],
[3, 8, 13, 18],
[4, 9, 14, 19]],
[[20, 25, 30, 35],
[21, 26, 31, 36],
[22, 27, 32, 37],
...
>> d.transpose(2,1,0)
=> Num::DFloat#shape=[5,4,3]:
[[[0, 20, 40],
[5, 25, 45],
[10, 30, 50],
[15, 35, 55]],
[[1, 21, 41],
[6, 26, 46],
[11, 31, 51],
[16, 36, 56]],
...
Contents ##.sum
Adds the elements specified together. Returns ether a NArray of values or a single value.
Returns: The Sumation value.
Options: -.sum(x) - adds elements in the specified dimension (e.g. '0'dimension -- 'x'dimension); -.sum(x,y,z,...) - adds elements in the specified dimensions; -.sum - adds all elements together
###Examples:
>> a = Num::DFloat.new([2,3]).seq
=> Num::DFloat#shape=[2,3]:
[[0, 1, 2],
[3, 4, 5]]
>> a.sum
=> 15.0
>> a.sum(0)
=> Num::DFloat#shape=[3]:
[3, 5, 7]
>> a.sum(1)
=> Num::DFloat#shape=[2]:
[3, 12]
>> a.sum(0,1)
=> 15.0
Contents ##.size
Appears to be an alias of length and total. Returns the size of the flattened NArray. Will return 1 for an array with no specified shape. Will return the total number of elements, even if those elements are nil. See Also: .total, .length
Returns: An integer value.
Options: None.
###Examples:
>> a = Num::DFloat.new([2,2,2]).seq
=> Num::DFloat#shape=[2,2,2]:
[[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]]
>> a.size
=> 8
>> a = Num::DFloat.new()
=> Num::DFloat#shape=[](no data)
>> a.size
=> 1
>> a = Num::DFloat.new([2,2,2])
=> Num::DFloat#shape=[2,2,2](no data)
>> a.size
=> 8
Contents ##.to_a
Returns the NArray as an array with all elements formatted as a multilayer structure of arrays containing the elements. Different than format_to_a, does not return float arrays as strings.
Returns: An array with same value types.
Options: none
###Examples:
>> a = Num::DFloat.new([2,2,2]).seq
=> Num::DFloat#shape=[2,2,2]:
[[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]]
>> a.to_a
=> [[[0.0, 1.0], [2.0, 3.0]], [[4.0, 5.0], [6.0, 7.0]]]
>> b = a.to_a[0]
=> [[0.0, 1.0], [2.0, 3.0]]
>> b[0]
=> [0.0, 1.0]
>> c = b[0]
=> [0.0, 1.0]
>> c[0].is_a?Float
=> true
Contents ##.total
Returns the total number of elements in the NArray. See Also: .size, .length
Returns: An integer value.
Options: none
###Examples:
>> a = Num::DFloat.new([2,2,3]).seq
=> Num::DFloat#shape=[2,2,3]:
[[[0, 1, 2],
[3, 4, 5]],
[[6, 7, 8],
[9, 10, 11]]]
>> a.total
=> 12
>> a = Num::DFloat.new([2,2,1]).seq
=> Num::DFloat#shape=[2,2,1]:
[[[0],
[1]],
[[2],
[3]]]
>> a.total
=> 4