N-Dimensional arrays
In numluau, most of your math is going to be done using N-Dimensional Arrays.
creating N-Dimensional arrays¶
the easiest way is to create a array it using a table.
Arrays simplify operations that would be otherwise tedious using regular tables. Removing the need for long for loops and table allocations.
using regular tables
local a = {1,2,3,4,5}
local b = {10,20,30,40,50}
local c = {}
for i = 1,5 do
c[i] = a[i] + b[i]
end
print(c) -- array([11 22 33 44 55])
using arrays
local a = numluau.array({1,2,3,4,5})
local b = numluau.array({10,20,30,40,50})
local c = a + b
print(c) -- array([11 22 33 44 55])
Arrays can also take in nested tables, to represent higher dimensional arrays
restrictions to arrays¶
there are restrictions when making a array
- all items must have the same data type
- the shape of the array must be retangular not jagged
- once created, you cannot change the size of an array
0d arrays¶
While you can make arrays 2d, 3d, 4d etc. you can also create 0d arrays. These arrays represent a single value.
To retrieve the value from this array you can use :Item().
properties of Arrays¶
- dtype - The data type of the items of the array.
- ndim - The dimension of the array.
- shape - A table that determins the dimensions of the array.
- strides - A table that describes how to index the array.
- buffer - The raw table that holds the data.
- offset - Determines the first item of the array.