A lightweight numpy-like library focusing on core array operations with threading and multiprocessing support.
- Core Array Class: Basic numpy-like array with indexing, reshaping, and data manipulation
- Arithmetic Operations: Element-wise add, subtract, multiply, divide
- Statistical Functions: Sum, mean, max, min with parallel versions
- Parallel Computing: Threading and multiprocessing support for performance
- Easy to Use: Simple API similar to NumPy
# Clone or download the project
cd mininumpy/
python demo.py # Run the demoimport mininumpy as mnp
# Create arrays
a = mnp.zeros((1000, 1000))
b = mnp.ones((1000, 1000))
# Basic operations
c = mnp.add(a, b)
total = mnp.sum(c)
# Parallel operations
c_parallel = mnp.add_parallel(a, b, n_threads=4)
total_parallel = mnp.sum_parallel(c, n_threads=4)mininumpy/
├── core/
│ ├── __init__.py
│ └── array.py # MiniArray class
├── operations/
│ ├── __init__.py
│ ├── arithmetic.py # Basic math operations
│ └── stats.py # Statistical functions
├── parallel/
│ ├── __init__.py
│ └── parallel.py # Threading/multiprocessing
├── tests/
│ └── test_basic.py # Unit tests
├── examples/
│ └── demo.py # Demonstration script
└── README.md
cd tests/
python test_basic.pyThe library shows performance improvements with parallel operations on large arrays:
- Threading: Best for I/O bound and shared memory operations
- Multiprocessing: Best for CPU-intensive computations
See demo.py for detailed benchmarking results.
MiniArray(data, shape=None, dtype='float64')- Create array from datazeros(shape)- Create array filled with zerosones(shape)- Create array filled with onesarange(start, stop, step=1)- Create array with range of values
add(a, b)- Element-wise additionsubtract(a, b)- Element-wise subtractionmultiply(a, b)- Element-wise multiplicationdivide(a, b)- Element-wise divisionadd_parallel(a, b, n_threads=4)- Parallel additionmultiply_parallel(a, b, n_processes=2)- Parallel multiplication
sum(array)- Sum all elementsmean(array)- Calculate meanmax(array)- Find maximum valuemin(array)- Find minimum valuesum_parallel(array, n_threads=4)- Parallel summean_parallel(array, n_threads=4)- Parallel mean
# Import the library
import mininumpy as mnp
# Create and manipulate arrays
arr = mnp.MiniArray([1, 2, 3, 4, 5, 6], shape=(2, 3))
print(f"Array shape: {arr.shape}")
print(f"Element at [1,1]: {arr[1, 1]}")
# Reshape operations
reshaped = arr.reshape((3, 2))
flattened = arr.flatten()
# Mathematical operations
a = mnp.ones((1000,))
b = mnp.arange(0, 1000)
result = mnp.add(a, b)
# Statistical analysis
total = mnp.sum(result)
average = mnp.mean(result)
# Parallel computing for large datasets
large_a = mnp.zeros((100000,))
large_b = mnp.ones((100000,))
# Compare performance
import time
# Sequential
start = time.time()
seq_result = mnp.add(large_a, large_b)
seq_time = time.time() - start
# Parallel
start = time.time()
par_result = mnp.add_parallel(large_a, large_b, n_threads=4)
par_time = time.time() - start
print(f"Sequential: {seq_time:.4f}s")
print(f"Parallel: {par_time:.4f}s")
print(f"Speedup: {seq_time/par_time:.2f}x")- Arrays are stored as flat Python lists with shape metadata
- Parallel operations split work across threads/processes
- Thread-based parallelism for shared memory operations
- Process-based parallelism for CPU-intensive tasks
- Error handling for shape mismatches and invalid operations
- No broadcasting (arrays must have same shape)
- Limited to basic operations (no advanced linear algebra)
- Python lists instead of optimized C arrays
- No GPU acceleration
- Matrix multiplication
- Advanced slicing operations
- Broadcasting support
- GPU acceleration with numba
- More statistical functions
- Linear algebra operations
This is an educational project. Feel free to extend with additional features:
- Add new mathematical operations
- Implement advanced indexing
- Add more statistical functions
- Optimize performance
- Add GPU support
Educational/demonstration purposes. Feel free to modify and extend.