Skip to content

Commit 788e139

Browse files
committed
update readme to have examples
1 parent 52e6018 commit 788e139

File tree

1 file changed

+79
-18
lines changed

1 file changed

+79
-18
lines changed

README.md

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@
44
<img src="https://github.com/ScottBoyce-Python/DateIntervalCycler/actions/workflows/python-pytest.yml/badge.svg" alt="Build Status" height="20">
55
</p>
66

7-
DynamicVector is a numpy based Python object that stores a vector that can dynamically increase in size. This array supports many python list methods and all the numpy methods. The underlaying numpy array and automatically sized to meet the storate need of the vector.
7+
DynamicVector is a Python class designed to combine the flexibility of Python lists with the computational efficiency of NumPy arrays. It allows for dynamic resizing, list-like manipulation, and full access to NumPy’s powerful numerical operations.
88

9+
## Features
910

11+
- **Dynamic Resizing**: Automatically expands as new elements are appended or inserted, mimicking Python lists.
12+
- **NumPy Integration**: Access to all NumPy array operations and methods via the `view` property.
13+
- **List-Like Functionality**: Supports common list operations such as append, insert, and pop, making it highly versatile.
14+
- **Optimized for Performance**: Takes advantage of NumPy’s speed and memory efficiency for handling large datasets.
1015

1116
## Installation
17+
Ensure that `numpy` is installed in your environment. If not, you can install it using:
18+
(note, this module was only tested against `numpy>2.0`)
19+
20+
```bash
21+
pip install numpy
22+
```
23+
1224
To install the module
25+
1326
```bash
1427
pip install --upgrade git+https://github.com/ScottBoyce-Python/DynamicVector.git
1528
```
@@ -22,43 +35,91 @@ and then move the file `DynamicVector/DynamicVector.py` to wherever you want to
2235

2336

2437
## Usage
25-
DynamicVector `from_` constructors example:
38+
39+
Below are examples showcasing how to create and interact with a `DynamicVector`.
40+
41+
### Creating a Vector
2642

2743
```python
28-
# EXAMPLES GO HERE
44+
from DynamicVector import DynamicVector
45+
46+
# Initialize with a list
47+
vec = DynamicVector.from_values([1, 2, 3]) # integer vector with three values
48+
print(vec) # Output: DynamicVector([1, 2, 3])
49+
print(repr(vec)) # Output: DynamicVector([1, 2, 3], dtype=int32)
2950
```
3051

31-
&nbsp;
52+
### Using NumPy Functions
3253

33-
After running the previous code, the terminal output is:
54+
```python
55+
# Access the underlying NumPy array via the 'view' property
56+
print(vec.view) # Output: [1 2 3]
57+
print(vec[:]) # Output: [1 2 3] -> same as vec.view
3458

35-
```
36-
# EXAMPLES GO HERE
37-
```
59+
# Perform NumPy operations
60+
vec += 1
61+
print(vec) # Output: DynamicVector([2, 3, 4])
3862

39-
&nbsp;
63+
vec[1] = 99
64+
print(vec) # Output: DynamicVector([ 2, 99, 4])
4065

41-
Here is a full example of the DateIntervalCycler class:
66+
vec[1:len(vec)] = 8 # set element 2 and 3 to the value of 8.
67+
print(vec) # Output: DynamicVector([2, 8, 8])
4268

43-
```python
44-
# EXAMPLES GO HERE
69+
vec[:] = [2, 3, 4]
70+
print(vec) # Output: DynamicVector([2, 3, 4])
4571
```
4672

47-
&nbsp;
73+
### Appending and Adding Elements
74+
75+
```python
76+
# Append elements dynamically
77+
vec.append(5) # Fast operation
78+
print(vec) # Output: DynamicVector([2, 3, 4, 5])
4879

49-
After running the previous code, the terminal output is:
80+
vec.extend([7, 8, 9]) # Fast operation
81+
print(vec) # Output: DynamicVector([1, 2, 3, 5, 7, 8, 9])
5082

83+
# Insert at a specific index
84+
vec.insert(1, 10)
85+
print(vec) # Output: DynamicVector([ 1, 10, 2, 3, 5, 7, 8, 9])
86+
87+
# Insert at a specific index
88+
vec.insert_values(3, [97, 98])
89+
print(vec) # Output: DynamicVector([ 1, 10, 2, 97, 98, 3, 5, 7, 8, 9])
5190
```
52-
# EXAMPLES GO HERE
91+
92+
### Popping Elements
93+
94+
```python
95+
# Remove and return the last element
96+
print(vec) # Output: DynamicVector([ 1, 10, 2, 97, 98, 3, 5, 7, 8, 9])
97+
last_elem = vec.pop() # Fast operation
98+
print(vec) # Output: DynamicVector([ 1, 10, 2, 97, 98, 3, 5, 7, 8])
99+
print(last_elem) # Output: 9
100+
101+
third_element = vec.pop(2)
102+
print(vec) # Output: DynamicVector([ 1, 10, 97, 98, 3, 5, 7, 8])
103+
print(third_element) # Output: 2
53104
```
54105

106+
### Slicing
55107

108+
```python
109+
# Slice behaves like NumPy arrays
110+
sliced_vec = vec[1:3]
111+
print(sliced_vec) # Output: [10 97]
56112

57-
## Testing
113+
vec[2:5] = [51, 52, 53]
114+
print(vec) # Output: DynamicVector([ 1, 10, 51, 52, 53, 5, 7, 8])
58115

59-
This project uses `pytest` and `pytest-xdist` for testing. Tests are located in the `tests` folder. Tests that are very slow are marked as being "slow". The `tests` directory contains multiple subdirectories that contain equivalent slow tests are divided into multiple files to improve parallel execution. The original, slow tests are marked as "slow_skip" and skipped, while the subdirectory tests are marked as "subset".
116+
vec[[1, 3, 5]] = [-1, -2, -3]
117+
print(vec) # Output: DynamicVector([ 1, -1, 51, -2, 53, -3, 7, 8])
118+
```
119+
120+
## Testing
60121

61-
To run tests, install the required packages and execute the following command:
122+
This project uses `pytest` and `pytest-xdist` for testing. Tests are located in the `tests` folder. To run tests, install the required packages and execute the following command:
62123

63124
```bash
64125
pip install pytest pytest-xdist

0 commit comments

Comments
 (0)