A simple yet powerful multi-dimensional array implementation in C++11, inspired by Python's NumPy. This library provides an intuitive interface for working with multi-dimensional arrays, supporting slicing, indexing, and initialization through initializer lists.
- Multi-dimensional arrays: Supports arrays with arbitrary dimensions, enabling complex data structures.
- Initializer list support: Easily initialize arrays with nested lists.
- Indexing and slicing: Access and manipulate data through familiar Python-like syntax.
- C++11 support: Fully compatible with C++11 and upper, using modern type traits and std::initializer_list.
To use Ndarray-11, simply download or clone the repository and include the header file in your project.
Then, include the header file in your code:
#include "ndarray-11.hpp"
- For more examples, see the examples directory.
- Documentation is generated using Doxygen, and can be found here.
Create a 3D array with pre-defined dimensions:
pp::Ndarray<int[3]> array = {
{
{0, 0, 0},
{0, 0, 0}
},
{
{1, 1, 1},
{1, 1, 1}
}
};
Access elements with an intuitive function call syntax, similar to Python's NumPy:
array(0, 1, 2) = 777; // Equivalent to array[0][1][2] = 777;
Perform slicing operations with a Python-like syntax using the Range
class:
auto sliced_array = array["0:1, ::1"];
Print the array using the <<
operator:
std::cout << array << std::endl;
#include "ndarray-11.hpp"
int main() {
pp::Ndarray<int[3]> array = {
{
{0, 0, 0},
{0, 0, 0}
},
{
{1, 1, 1},
{1, 1, 1}
}
};
// Set value at [0][1][2]
array(0, 1, 2) = 777;
// Print the array
std::cout << array << std::endl;
return 0;
}
- Negative indices when slicing are not supported yet. #1
- Broadcasting is not supported yet.
- Dimensions must remain the same after slicing. #2
- Dimensions must be specified at compile time.
Check out the Milestones
Contributions are welcome! If you find bugs or have suggestions for improvements, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
- @rexwolflan for technical guidance and code review.