Ad Code

Responsive Advertisement

Basic Python Program - 47

Question 47: Write a Python program to create two matrices and perform addition, subtraction, multiplication and division operation on matrix.
Download hole Program / Project code, by clicking following link:
Describe Numpy Array in Python ?
NumPy (Numerical Python) is a popular library in Python for numerical and mathematical operations. One of the key components of NumPy is the ndarray, or NumPy array, which is an efficient, multi-dimensional array object for storing and manipulating large sets of data.

Here are some key characteristics and features of NumPy arrays:
  1. Homogeneous Data: NumPy arrays are homogeneous, which means they can contain elements of the same data type (unlike Python lists, which can hold elements of different data types). This homogeneity makes NumPy arrays efficient for mathematical and numerical operations.
  2. Multi-Dimensional: NumPy arrays can have multiple dimensions, allowing you to work with matrices and tensors efficiently. They can be one-dimensional (like a vector), two-dimensional (like a matrix), or even higher-dimensional.
  3. Efficiency: NumPy arrays are highly optimized for numerical operations and consume less memory than Python lists. This makes them well-suited for working with large datasets.
  4. Broadcasting: NumPy allows for broadcasting, which simplifies operations on arrays with different shapes. This means you can perform element-wise operations on arrays with different shapes, and NumPy handles the broadcasting automatically.
  5. Universal Functions (ufuncs): NumPy provides a wide range of mathematical functions and operations that work element-wise on arrays. These functions are called universal functions (ufuncs) and include basic mathematical operations, trigonometric functions, statistical functions, and more.
  6. Indexing and Slicing: You can access elements of a NumPy array using indexing and slicing, similar to Python lists. NumPy provides advanced indexing techniques, such as boolean indexing and fancy indexing, which allow for more complex and powerful selections.
Here's an example of creating a simple NumPy array:
import numpy as np
# Create a 1D NumPy array
arr = np.array([1, 2, 3, 4, 5])
# Perform operations on the array
result = arr * 2
print(result)
In this example, we import NumPy as np, create a 1D NumPy array, and then multiply all elements of the array by 2 using a simple operation.

NumPy is widely used in various domains, such as data science, machine learning, scientific computing, and engineering, due to its efficiency and versatility in handling numerical data and performing mathematical operations.
Programming Code:
Following code write in: BP_P47.py
# Pytho Program 

# Perform Operation on Matrices

# import lib.
import numpy as np

# Create first Matrix
mat1 = np.array([[2, 5], [7, 5]])

# Create Second Matrix
mat2 = np.array([[25, 3], [9, 7]])

print("Printing elements of First matrix")
print(mat1)

print("Printing elements of Second matrix")
print(mat2)

# Adding two Matrix
print("\nAddition of Matrix is: ")
print(np.add(mat1, mat2))

# Subtraction of Matrix
print("\nSubtraction of Matrix is: ")
print(np.subtract(mat1, mat2))

# Multiply tow matrix
print("\nMultiplication of Matrix is: ")
print(np.multiply(mat1, mat2))

# division of two matrix
print("\nDivision of Matrix is: ")
print(np.divide(mat1, mat2))

# Thanks for Reading.
Output:

Post a Comment

0 Comments

Ad Code

Responsive Advertisement