Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/n4ze3m/matrix2d
A package for mathematical 2D array functions and manipulations in Dart, similar to NumPy
https://github.com/n4ze3m/matrix2d
dart dartlang matrix numpy
Last synced: 19 days ago
JSON representation
A package for mathematical 2D array functions and manipulations in Dart, similar to NumPy
- Host: GitHub
- URL: https://github.com/n4ze3m/matrix2d
- Owner: n4ze3m
- License: mit
- Created: 2020-07-25T11:53:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-29T07:07:10.000Z (over 1 year ago)
- Last Synced: 2024-11-23T21:02:58.763Z (about 1 month ago)
- Topics: dart, dartlang, matrix, numpy
- Language: Dart
- Homepage: https://pub.dev/packages/matrix2d
- Size: 92.8 KB
- Stars: 16
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Matrix 2D 🧮
[![pub version](https://img.shields.io/pub/v/matrix2d.svg)](https://pub.dev/packages/matrix2d)
[![Build Status](https://github.com/n4ze3m/matrix2d/actions/workflows/ci.yml/badge.svg)](https://github.com/n4ze3m/matrix2d/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/github/license/n4ze3m/matrix2d)](https://github.com/n4ze3m/matrix2d/blob/master/LICENSE)With Matrix 2D, you can perform matrix operations such as addition, subtraction, and multiplication in Dart. It is a simple and easy-to-use library inspired by Python's NumPy library.
## Operations
- `addition(listA,listB)` returns array of sums of corresponding elements of listA and listB of any dimensions.
- `subtraction(listA,listB)` returns array of differences of corresponding elements of listA and listB of any dimensions.
- `division(listA,listB)` divides listA by listB and returns new array
- `dot(listA,listB)` Function returns the dot product of two arrays. For 2-D vectors, it is the equivalent to matrix multiplication. For 1-D arrays, it is the inner product of the vectors. For N-dimensional arrays, it is a sum product over the last axis of a and the second-last axis of b.
- `shape(list)` returns dimensions of input array if the array is uniform or error otherwise.
- `flatten(list)` returns 1-D representation of any shape and any levels of nesting of list array.
- `transpose(list)` Reverse the axes of an array and returns the modified array
- `arange(start, stop, steps)` returns evenly spaced values within the half-open interval `[start, stop)` with optional steps argument.
- `zeros(row,cols)` Return a new array of given shape and type, with zeros
- `ones(row,cols)` Return a new array of given shape and type, with ones
- `sum(list)` Function returns the sum of array elements
- `reshape(list)`Reshaping means changing the shape of an array.
- `diagonal(list)` To find a diagonal element from a given matrix and gives output as one dimensional matrix.
- `fill(row,cols,object)` Just like `zeros()` and `ones` this function will return a new array of given shape, with given object(anything btw strings too)* `compareobject(list,operation,obj)` compare values inside an array with given object and operations. function will return a new boolen array (this function is deprecated in favor of `compare`)
* `concatenate(listA,listB,{axis})` Concatenation refers to joining. This function is used to join two arrays of the same shape along a specified axis. The function takes the following parameters.Axis along which arrays have to be joined. Default is 0
* `min(list,{axis})` Functions, used to find the minimum value for any given array
* `max(list,{axis})` Functions, used to find the maximum value for any given array
* `slice(list (List), row_index [start, stop*], column_index [start, stop*]*)` Function used to slice two-dimensional arrays . (_column_index_ and _stop_ not required )
* `reverse(list,{axis})` Function used to reverse the array along the given axis. The function takes the following parameters.Axis along which the array is to be flipped. Default is 0
## Examples
shape
```dart
List list = [[1, 2],[1, 2]];
print(list.shape);
```ouput:
```cmd
[2,2]
```
flatten
```dart
List list = [[1, 2],[1, 2]];
print(list.flatten);
```ouput:
```cmd
[1,2,1,2]
```
transpose
```dart
List list = [[1, 2],[1, 2]];
print(list.transpose);
```ouput:
```cmd
[[1,1],[2,2]]
```
addition
```dart
List list1 = [[1, 1],[1, 1]];
List list2 = [[2, 2],[2, 2]];
var addition = m2d.addition(list1,list2);
print(addition);
```ouput:
```cmd
[[3,3],[3,3]]
```
subtraction
```dart
List list1 = [[1, 1],[1, 1]];
List list2 = [[2, 2],[2, 2]];
var subtraction = m2d.subtraction(list1,list2);
print(subtraction);
```ouput:
```cmd
[[-1,-1],[-1,-1]]
```
division
```dart
List list1 = [[1, 1],[1, 1]];
List list2 = [[2, 2],[0, 2]];
var division = m2d.subtraction(division,list2);
print(division);
```ouput:
```cmd
[[0.5,Infinity],[0.5,0.5]]
```
dot operation
```dart
List list1 = [[1,2],[3,4]];
List list2 = [[11,12],[13,14]];
var dot = m2d.dot(division,list2);
print(dot);
```ouput:
```cmd
[[37, 40], [85, 92]]
```
arange
```dart
var arange = m2d.arange(8);
print(arange);
```ouput:
```cmd
[[0,1,2,3,4,5,6,7,8]]
```
sum
```dart
var list = [[2,2],[2,2]];
var sum = m2d.sum(list);
print(sum);
```ouput:
```cmd
8
```
reshape
```dart
List list = [[0, 1, 2, 3, 4, 5, 6, 7]];
list = list.reshape(2,4);
print(list);
```ouput:
```cmd
[[0, 1, 2, 3], [4, 5, 6, 7]]
```
linspace
```dart
var linspace = m2d.linspace(2, 3, 5);
print(linspace);
```ouput:
```cmd
[2.0, 2.25, 2.5, 2.75, 3.0]
```
diagonal
```dart
List list = [[1,1,1],[2,2,2],[3,3,3]];
print(list.diagonal);
```ouput:
```cmd
[1,2,3]
```
compare
```dart
var list = [[1,1,1],[2,2,2],[3,3,3]];
var compare = m2d.compare(list,'>',2);
print(compare);
```ouput:
```cmd
[[false, false, false], [false, false, false], [true, true, true]]
```
concatenate
axis 0
```dart
final l1 = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
];
final l2 = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
];
final l3 = m2d.concatenate(l1, l2);
print(l3);
```ouput:
```cmd
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]
```axis 1
```dart
final a1 = [
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]
];
final a2 = [
[0, 0, 0, 0, 0,0, 0, 0, 0, 0],
[0, 0, 0, 0, 0,0, 0, 0, 0, 0],
[0, 0, 0, 0, 0,0, 0, 0, 0, 0]
];final a3 = m2d.concatenate(a2, a1, axis: 1);
print(a3);
```ouput:
```cmd
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1]]
```
zeros,ones and fill
```dart
var zeros = m2d.zeros(2,2);
print(zeros);var ones = m2d.ones(2,2);
print(ones);var anything = m2d.fill(2,2,'i love dart');
print(anything);
```ouput:
```cmd
[[0,0],[1,1]][[1,1],[1,1]]
[['i love dart','i love dart'],['i love dart','i love dart']]
```
min max
```dart
final numbers = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
print(numbers.min());
print(numbers.min(axis: 1));
print(numbers.min(axis: 0));
print(numbers.max());
print(numbers.max(axis: 1));
print(numbers.max(axis: 0));
```ouput:
```cmd
[1][1, 4, 7]
[1, 2, 3]
[9]
[3, 6, 9]
[7, 8, 9]
```slice
```dart
var sliceArray = [
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10]
];var newArray = m2d.slice(sliceArray, [0, 2], [1, 4]);
print(newArray);```
ouput:
```cmd
[[2, 3, 4],[7, 8, 9]]
```## Contribution
If you want to contribute to this project, you are always welcome! Just make a pull request and I will review it as soon as possible.
## Features and bugs
If you have any problems or suggestions, please open an issue [here](https://github.com/n4ze3m/matrix2d/issues).