test "functions on arrays" {
inspect!(
@nm.array([0.1, 0.2, 0.3])
.sin()
.cos()
.arccos()
.arcsin()
.multiply(10)
.round()
.divide(10),
content="[0.1,0.2,0.3]",
)
}
test "slice" {
let arr = @nm.array([1, 2, 3, 4, 5])
inspect!(arr[2:4], content="[3,4]")
}
Numoon is an open-source MoonBit library that provides support for multi-dimensional array objects and functions for efficiently operating on these arrays.
Here are some key features of Numoon:
-
Multi-dimensional Array Objects: Numoon provides a powerful N-dimensional array NMArray, which is the foundation for scientific computing.
-
Derived Objects (such as Masked Arrays and Matrices): Numoon allows users to create special arrays, like masked arrays, which handle missing or invalid data.
-
Extensive Mathematical Function Library: Numoon has a vast array of mathematical functions, including linear algebra, Fourier transforms, and random number generation.
Numoon is an indispensable tool for scientific computing and data analysis in MoonBit, widely used in fields such as physics, biology, engineering, and more.
To get started with Numoon, you can simply install it using the following command:
moon add oboard/numoon
Configure your MoonBit project moon.pkg.json
file:
{
"import": [
{
"path": "oboard/numoon/lib",
"alias": "nm"
}
]
}
This will install the latest version of Numoon and its dependencies.
To use Numoon in your MoonBit program, simply import the library using the following code:
You can then create an NMArray object using the following code:
a = @nm.array([1, 2, 3])
b = @nm.array([1, 2, 3])
println(a + b)
// Output: [2, 4, 6]
a = @nm.array([1, 2, 3])
println(a.sum())
println(a.prod())
// Output: 6 6
let a = @nm.array([[1, 2, 3], [4, 5, 6]])
println(a.reshape(3, 2))
// Output: [[1, 2], [3, 4], [5, 6]]
let list1 = @nm.rand(6)
println(list1)
// Output: [[0.2893123275883688, 0.33959090191249325, 0.1521095035725017],
// 0.9314055834969763, 0.8561914513327412, 0.7919828439328577]
let list1 = @nm.array([[1, 2, 3], [4, 5, 6]])
let m2 = @nm.array([[1, 2, 3], [4, 5, 6]])
let m1 = @nm.array([[7, 8], [9, 10], [11, 12]])
let result = @nm.dot(m1, m2)
println(result)
// Output: [[121.0 136.0 151.0]
// [153.0 172.0 191.0]
// [185.0 208.0 231.0]]
let a = @nm.array([[1, 2], [3, 4]])
println(a.transpose())
// Output: [[1 3]
// [2 4]]
start: The starting value of the sequence.
stop: The ending value of the sequence.
~num: The number of samples to generate, inclusive of both start and stop. Default is 50.
let a = @nm.linspace(0.0, 10.0, num=11)
println(a)
// Output: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
We welcome contributions to Numoon! Please read our contribution guide to learn more.
- @oboard
- @Yorkin
This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details.