NumPy is an open-source numerical computing library for Python. It provides support for large, multi-dimensional arrays and matrices, along with mathematical functions to operate on these arrays. NumPy is a fundamental package for scientific computing in Python and is used in various fields such as machine learning, data science, and engineering.
import numpy as np
# Create a NumPy array
arr = np.array([1, 2, 3, 4, 5])
# Perform operations on the array
squared_arr = np.square(arr)
sum_squared = np.sum(squared_arr)
# Create a 2D NumPy array
matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# Perform operations on the matrix
transpose_matrix = np.transpose(matrix)
matrix_det = np.linalg.det(matrix)
# Display results
print("Original Array:")
print(arr)
print("\nSquared Array:")
print(squared_arr)
print("\nSum of Squared Elements:")
print(sum_squared)
print("\nOriginal Matrix:")
print(matrix)
print("\nTransposed Matrix:")
print(transpose_matrix)
print("\nDeterminant of Matrix:")
print(matrix_det)
This example demonstrates using NumPy for numerical computing in Python:
Feel free to run this code in a Python environment with NumPy installed to explore the capabilities of this powerful numerical computing library!
To install NumPy, you can use the following command:
pip install numpy