Skip to content

Commit eff6ee5

Browse files
Update numpy.md
1 parent 02f045d commit eff6ee5

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

Modules and Packages/numpy.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ print("Original Array:", array)
3030
print("Squared Array:", squared_array)
3131
```
3232

33-
# Creating a sample matrix
33+
### Creating a sample matrix
3434
```python
3535
matrix = npy.array([[1, 2], [3, 4]])
3636

@@ -40,3 +40,66 @@ transposed_matrix = npy.transpose(matrix)
4040
print("Original Matrix:\n", matrix)
4141
print("Transposed Matrix:\n", transposed_matrix)
4242
```
43+
44+
### Array Arithmetic Operations
45+
46+
```python
47+
# Creating two sample arrays
48+
array1 = npy.array([1, 2, 3, 4, 5])
49+
array2 = npy.array([5, 4, 3, 2, 1])
50+
51+
# Adding the arrays
52+
sum_arrays = npy.add(array1, array2)
53+
54+
# Subtracting the arrays
55+
diff_arrays = npy.subtract(array1, array2)
56+
57+
# Multiplying the arrays element-wise
58+
product_arrays = npy.multiply(array1, array2)
59+
60+
# Dividing the arrays element-wise
61+
quotient_arrays = npy.divide(array1, array2)
62+
63+
print("Array1:", array1)
64+
print("Array2:", array2)
65+
print("Sum:", sum_arrays)
66+
print("Difference:", diff_arrays)
67+
print("Product:", product_arrays)
68+
print("Quotient:", quotient_arrays)
69+
```
70+
### Reshaping an Array
71+
72+
```python
73+
# Creating a sample array
74+
array = npy.array([1, 2, 3, 4, 5, 6])
75+
76+
# Reshaping the array into a 2x3 matrix
77+
reshaped_array = npy.reshape(array, (2, 3))
78+
79+
print("Original Array:", array)
80+
print("Reshaped Array:\n", reshaped_array)
81+
```
82+
### Finding Maximum and Minimum Values
83+
```python
84+
# Creating a sample array
85+
array = npy.array([1, 3, 2, 5, 4])
86+
87+
# Finding the maximum value
88+
max_value = npy.max(array)
89+
90+
# Finding the minimum value
91+
min_value = npy.min(array)
92+
93+
print("Array:", array)
94+
print("Maximum Value:", max_value)
95+
print("Minimum Value:", min_value)
96+
```
97+
98+
### Generating a Range of Numbers
99+
```python
100+
# Generating a range of numbers from 0 to 9
101+
range_array = npy.arange(10)
102+
103+
print("Range Array:", range_array)
104+
```
105+

0 commit comments

Comments
 (0)