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)