1.
Answer the following
1. What is NumPy? Why should we use it?
NumPy (Numerical Python) is a powerful Python library used for numerical and scientific computing. It provides
support for multi-dimensional arrays, mathematical functions, linear algebra, statistics, and more.
Why we use NumPy:
• It is faster than Python lists for numerical operations.
• Provides efficient array operations and broadcasting.
• Uses less memory compared to lists.
• Offers built-in functions for mathematics, statistics, and linear algebra.
• Widely used in Data Science, Machine Learning, and AI.
2. Steps to Create 2D and 3D Arrays (with Output)
Step 1: Import NumPy
import numpy as np
(a) Create a 2D Array
Steps:
1. Import NumPy.
2. Use [Link]() with a list of lists.
3. Print the array.
import numpy as np
arr_2d = [Link]([[1, 2, 3],
[4, 5, 6]])
print(arr_2d)
Output:
[[1 2 3]
[4 5 6]]
(b) Create a 3D Array
Steps:
1. Import NumPy.
2. Use [Link]() with a list of 2D arrays.
3. Print the array.
import numpy as np
arr_3d = [Link]([[[1, 2, 3],
[4, 5, 6]],
[[7, 8, 9],
[10, 11, 12]]])
print(arr_3d)
Output:
[[[ 1 2 3]
[ 4 5 6]]
[[ 7 8 9]
[10 11 12]]]