Python Assignment 1
Python Assignment 1
1. Program to find maximum value and minimum value form the given matrix
In [37]: import numpy as np
Maximum value: 9
Minimum value: 1
In [38]: #a. Find the number of rows and columns of a given matrix using NumPy:
import numpy as np
# Sample matrix
matrix = np.array([[1, 2, 3], [4, 5, 6]])
Number of rows: 2
Number of columns: 3
# Sample matrix
matrix = np.array([[1, 2, 3], [4, 5, 6]])
# Addition of matrices
result_add = np.add(matrix1, matrix2)
import numpy as np
# Subtraction of matrices
result_sub = np.subtract(matrix1, matrix2)
import numpy as np
# Matrix multiplication
result_mult = np.dot(matrix1, matrix2)
# Sample 1D array
arr = np.array([1, 2, 2, 3, 3, 3, 4])
import numpy as np
# Sample matrix
matrix = np.array([[1, 2], [3, 4]])
print(f"Matrix as a list:",matrix_list)
import numpy as np
# Sample array
arr = np.array([-1, 2, -3, 4, -5])
import numpy as np
# Sample array
arr = np.array([[1, 2], [3, 4]])
import numpy as np
# Sample array
arr = np.array([1, 2, 3, 4, 5])
import numpy as np
# Sample array
arr = np.array([1, 2, 3, 4, 5])
import numpy as np
# Sample array
arr = np.array([1, 2, 3, 4, 5])
6. Create a 5X2 integer array from a range between 100 to 200 such that the difference between each element is 10:
In [35]: import numpy as np
print(f"5x2 array with elements from 100 to 200 with a difference of 10:")
print(arr)
5x2 array with elements from 100 to 200 with a difference of 10:
[[100 110]
[120 130]
[140 150]
[160 170]
[180 190]]
7. Return array of item by taking the third column from all rows:
In [36]: import numpy as np
In [ ]:
In [ ]:
In [ ]: