ICT finals Flashcards
(41 cards)
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)