ICT finals Flashcards
What is Numpy?
A python library for numerical computing
How can you install Numpy?
pip install numpy
What is the primary object type in Numpy?
ndarrays
How do you import Numpy in a Python script?
import numpy as np
What does the following code output: np.array([1, 2, 3, 4, 5])?
[1, 2, 3, 4, 5]
What are 0-D arrays in Numpy?
Scalars
What are 1-D arrays also known as?
Vectors
Which of the following is a 2-D array?
np.array([[1, 2, 3], [4, 5, 6]])
How does you access the second element of the first row in a 2-D array?
arr[0, 1]
What does negative indexing represent?
Accessing elements from the start
How do you slice elements from index 1 to 4 in an array?
arr[1:4]
What does arr[-3:-1] return?
The last three elements
What is the step in array slicing used for?
To skip elements in the array
What is the difference between a copy and a viewer of a Numpy array?
A copy owns the data, a view does not
What will arr[0] = 42 change in a view of an array?
It will update only the view
How can you iterate through each element in a 1-D Numpy array?
for x in arr: print(x)
What does np.ndenumerate() do?
Enumerates over ndarray sequence
What is the output of print(arr[1, -1])?
Prints the last element of the second row
What does arr[1:5:2] do?
Selects elements from index 1 to 2 with a step of 5
How do you select elements from the second row and columns 1 to 4 in a 2-D array?
arr[1, 1:4]
What does the shape attribute of a Numpy array return?
arr.reshape(2, 6)
How can you reshape a 1-D array with 12 elements into a 2-D array with 4 arrays, each containing 3 elements?
arr.reshape(4, 3)
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
What is the original shape of the array arr?
(12,)
What will be the new shape of an array after this operation: arr.reshape(2, 3, 2)
(3, 2, 2)
If you have a 2-D array and you iterate over it, what will you get?
Each row of the array
What does the concatenate() function do in Numpy?
Joins a sequence of arrays along an existing axis
How do you join two 1-D array along the second axis using Numpy?
np.stack((arr1, arr2), axis=1)
walang questionnaire and no.28 pero may sagot
np.vstack()
What is the result of splitting an array using np.array_split(arr, 3)?
A list containing three arrays
How can you search for the value ‘4’ in a NumPy array?
np.where(arr == 4)
What does the sort() function do in Numpy?
Orders the elements in an ascending od descending sequence
How do you filter an array to only include elements greater than 42?
arr[arr > 42]
quiz_scores = np.array([[85, 90, 92], [88, 82, 95], [75, 78, 80], ])
What is the shape of the quiz_scores array before reshaping?
(3, 3)
quiz_scores = np.array([[85, 90, 92], [88, 82, 95], [75, 78, 80], ])
After reshaping quiz_scores to calculate the average score of each student, what is the shape of the reshaped array?
(3, 3)
What is the average score of Student 2?
88.33333333333333
When iterating over a 3D array, what does each iteration provide?
A 2D array
What does the hsplit() function do?
Splits an array horizontally
How can you search for multiple values, such as 2, 4, and 6, in a NumPy array?
np.where(arr == [2, 4, 6])
What will be the shape of an array after the operation arr.reshape(1, 2, 3, 2)?
(1, 2, 3, 2)
If you want to filter a 2D array to get elements greater than 4, Which of the following is correct?
arr_2d[arr_2d > 4]
Pag nakalimutan ko sagot, pahinge
Yes lang ang sagot, wala kang choice :p