1.
Basic Array Creation
Question:
How do you create a 1D NumPy array with the values [10, 20, 30, 40, 50] ?
Answer:
import numpy as np
arr = [Link]([10, 20, 30, 40, 50])
arr
2. Array Indexing
Question:
Given the array arr = [Link]([10, 20, 30, 40, 50]) , how would you access the third element?
Answer:
arr = [Link]([10, 20, 30, 40, 50])
third_element = arr[2]
third_element
3. Slicing Arrays
Question:
How can you slice the first three elements from an array arr = [Link]([1, 2, 3, 4, 5]) ?
Answer:
arr = [Link]([1, 2, 3, 4, 5])
sliced_arr = arr[:3]
sliced_arr
4. Array Shape
Question:
What is the shape of a 3x2 matrix created using [Link]([[1, 2], [3, 4], [5, 6]]) ?
Answer:
arr = [Link]([[1, 2], [3, 4], [5, 6]])
arr_shape = [Link]
arr_shape
5. Array Broadcasting
Question:
What will be the result of adding [Link]([1, 2, 3]) to the 2D array [Link]([[4, 5, 6], [7, 8,
9]]) ?
Answer:
arr1 = [Link]([1, 2, 3])
arr2 = [Link]([[4, 5, 6], [7, 8, 9]])
result = arr2 + arr1
result
6. Reshaping Arrays
Question:
How would you reshape a 1D array of 9 elements arr = [Link](9) into a 3x3 matrix?
Answer:
arr = [Link](9)
reshaped_arr = [Link](3, 3)
reshaped_arr
7. Array Operations
Question:
What is the result of performing element-wise multiplication between two arrays a = [Link]([1, 2, 3])
and b = [Link]([4, 5, 6]) ?
Answer:
a = [Link]([1, 2, 3])
b = [Link]([4, 5, 6])
result = a * b
result
8. Array Sum
Question:
How can you calculate the sum of all elements in the array arr = [Link]([[1, 2], [3, 4]]) ?
Answer:
arr = [Link]([[1, 2], [3, 4]])
arr_sum = [Link](arr)
arr_sum
9. Mean, Median, and Standard Deviation
Question:
How would you compute the mean, median, and standard deviation of the array arr = [Link]([10, 20,
30, 40, 50]) ?
Answer:
arr = [Link]([10, 20, 30, 40, 50])
mean = [Link](arr)
median = [Link](arr)
std_dev = [Link](arr)
mean, median, std_dev
10. Array Minimum and Maximum
10. Array Minimum and Maximum
Question:
How would you find the minimum and maximum values of the array arr = [Link]([100, 200, 300, 400,
500]) ?
Answer:
arr = [Link]([100, 200, 300, 400, 500])
arr_min = [Link](arr)
arr_max = [Link](arr)
arr_min, arr_max
11. Creating a Zeros Array
Question:
How do you create a 3x3 matrix of zeros using NumPy?
Answer:
zeros_arr = [Link]((3, 3))
zeros_arr
12. Creating an Identity Matrix
Question:
How do you create a 4x4 identity matrix using NumPy?
Answer:
identity_matrix = [Link](4)
identity_matrix
13. Creating a Full Array
Question:
How would you create a 2x3 array filled with the value 7 using NumPy?
Answer:
full_array = [Link]((2, 3), 7)
full_array
14. Array Concatenation
Question:
How would you concatenate two arrays a = [Link]([1, 2, 3]) and b = [Link]([4, 5, 6]) into
one array?
Answer:
a = [Link]([1, 2, 3])
b = [Link]([4, 5, 6])
concatenated_array = [Link]((a, b))
concatenated_array
15. Array Stacking
Question:
How would you stack two arrays a = [Link]([1, 2, 3]) and b = [Link]([4, 5, 6]) vertically?
Answer:
a = [Link]([1, 2, 3])
b = [Link]([4, 5, 6])
stacked_array = [Link]((a, b))
stacked_array
16. Random Numbers
Question:
How would you generate a 2x3 matrix of random integers between 0 and 10?
Answer:
random_integers = [Link](0, 10, size=(2, 3))
random_integers
17. Array of Ones
Question:
How can you create a 3x3 matrix of ones using NumPy?
Answer:
ones_array = [Link]((3, 3))
ones_array
18. Using the where Function
Question:
How would you use [Link]() to return True for elements greater than 5 in the array arr =
[Link]([3, 6, 2, 8]) ?
Answer:
arr = [Link]([3, 6, 2, 8])
where_result = [Link](arr > 5, True, False)
where_result
19. Unique Elements
Question:
How can you find the unique elements of the array arr = [Link]([1, 1, 2, 2, 3, 3, 4]) ?
Answer:
arr = [Link]([1, 1, 2, 2, 3, 3, 4])
unique_elements = [Link](arr)
unique_elements
20. Creating a Full Array with full Function
Question:
Question:
How would you create a 3x3 array filled with the value 9 using the [Link]() function?
Answer:
full_array_9 = [Link]((3, 3), 9)
full_array_9
BY Pranjal Gajbhiye
Happy Learning...
In [ ]: