Untitled
unknown
plain_text
23 days ago
1.8 kB
2
Indexable
Never
1.Matrix Operations Using OOP and NumPy Create a Python class MatrixOperations that can handle basic matrix operations such as matrix addition, subtraction, and multiplication using NumPy. The class should include the following methods: • __init__(self, matrix): Initialize the object with a 2D NumPy array. • add(self, other_matrix): Add two matrices. • subtract(self, other_matrix): Subtract two matrices. • multiply(self, other_matrix): Multiply two matrices. Question: • Implement the MatrixOperations class. • Demonstrate its functionality by creating two matrices and performing all the operations. 2. Class for Nearest Neighbor Search using NumPy and OOP Generate set of random number set Design a Python class NearestNeighborSearch that finds the nearest neighbor of a given point from a set of points using Euclidean distance. The class should include: • __init__(self, points): Initialize the object with a 2D NumPy array representing multiple points. • find_nearest(self, point): Find and return the nearest point from the set based on Euclidean distance. 3. Polynomial Inheritance Using NumPy Create a base class Polynomial that stores the coefficients of a polynomial in a NumPy array and provides methods to evaluate the polynomial at a given point. Then create two subclasses: • Quadratic: Inherits from Polynomial and adds a method to find the roots of the quadratic polynomial. • Cubic: Inherits from Polynomial and adds a method to solve a cubic equation using NumPy's root-finding algorithms. Question: • Implement the Polynomial, Quadratic, and Cubic classes. • Instantiate both subclasses and evaluate the polynomial for a given input, as well as finding the roots of quadratic and cubic polynomials.
Leave a Comment