numpy Flashcards

(78 cards)

1
Q

Define NumPy.

A

A fundamental package for scientific computing in Python, providing support for arrays and matrices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does np.array() do?

A

It creates a NumPy array from a list or tuple.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or false: NumPy arrays can only hold one data type.

A

TRUE

NumPy arrays are homogeneous, meaning all elements must be of the same type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fill in the blank: ndarray stands for _______.

A

N-dimensional array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of np.zeros()?

A

To create an array filled with zeros of a specified shape.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Define broadcasting in NumPy.

A

A method that allows NumPy to perform arithmetic operations on arrays of different shapes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does np.shape() return?

A

The dimensions of a NumPy array as a tuple.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or false: NumPy supports complex numbers.

A

TRUE

NumPy can handle complex numbers using the ‘complex’ data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the result of np.arange(5)?

A

An array containing values [0, 1, 2, 3, 4].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Fill in the blank: np.reshape() changes the shape of an array without _______.

A

Changing its data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does np.mean() calculate?

A

The average of the elements in an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define slicing in NumPy.

A

Extracting a portion of an array using a range of indices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What error occurs with incompatible shapes in operations?

A

ValueError: shapes are not aligned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or false: NumPy can perform element-wise operations.

A

TRUE

Operations like addition and multiplication are applied element-wise.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does np.transpose() do?

A

It reverses the axes of an array, effectively transposing it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fill in the blank: np.concatenate() joins arrays along a _______.

A

specified axis

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the output of np.eye(3)?

A

A 3x3 identity matrix.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Define dtype in NumPy.

A

Data type of the elements in a NumPy array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does np.unique() return?

A

The unique elements of an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

True or false: NumPy arrays can be resized.

A

TRUE

Use the method ‘resize()’ to change the size of an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the purpose of np.random.rand()?

A

To generate an array of random numbers between 0 and 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Fill in the blank: np.dot() performs _______ product of two arrays.

A

dot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What does np.std() calculate?

A

The standard deviation of the elements in an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Define masking in NumPy.

A

Creating a boolean array to filter elements based on conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What error is raised when accessing an out-of-bounds index?
IndexError: index out of bounds.
26
True or false: NumPy can handle missing values.
TRUE ## Footnote Use 'np.nan' to represent missing values in arrays.
27
What does **np.linspace()** generate?
An array of evenly spaced numbers over a specified interval.
28
29
What does the **numpy.array** function do?
Creates an array from a list or tuple.
30
True or false: **numpy.zeros** creates an array of ones.
FALSE ## Footnote numpy.zeros creates an array filled with zeros.
31
Fill in the blank: **numpy.arange** generates values from start to _______.
stop
32
What are the arguments of **numpy.linspace**?
Start, stop, and number of samples.
33
Define **numpy.reshape**.
Changes the shape of an array without changing its data.
34
What does **numpy.sum** compute?
The sum of array elements over a specified axis.
35
True or false: **numpy.mean** calculates the median of an array.
FALSE ## Footnote numpy.mean calculates the average, not the median.
36
What does **numpy.concatenate** do?
Joins two or more arrays along an existing axis.
37
What does **numpy.random.rand** generate?
Random numbers from a uniform distribution over [0, 1).
38
True or false: **numpy.std** computes the standard deviation.
TRUE
39
Fill in the blank: **numpy.eye** creates a _______ matrix.
identity
40
What are the arguments of **numpy.split**?
Array to split, indices or sections.
41
Define **numpy.vstack**.
Stacks arrays vertically (row-wise).
42
What does **numpy.hstack** do?
Stacks arrays horizontally (column-wise).
43
True or false: **numpy.clip** limits the values in an array.
TRUE
44
Fill in the blank: **numpy.where** returns the indices of elements that satisfy a _______.
condition
45
What does **numpy.argsort** return?
Indices that would sort an array.
46
Define **numpy.cumsum**.
Computes the cumulative sum of array elements.
47
What is the purpose of **numpy.cumprod**?
Calculates the cumulative product of array elements.
48
True or false: **numpy.fill** fills an array with a specified value.
FALSE ## Footnote Use numpy.fill to fill an array, but it's not a standalone function.
49
Fill in the blank: **numpy.meshgrid** creates coordinate matrices from _______.
coordinate vectors
50
What does **numpy.isin** check?
Tests if elements of one array are in another.
51
Define **numpy.flatnonzero**.
Returns the indices of non-zero elements in an array.
52
What does **numpy.nonzero** return?
The indices of the elements that are non-zero.
53
What does the **sort** function do?
It arranges the elements of an array in a specified order.
54
True or false: **sort** can only sort numbers.
FALSE ## Footnote The sort function can also sort strings and objects based on specified criteria.
55
Fill in the blank: The **repeat** function creates an array with _______ elements.
Repeated values
56
What is the purpose of the **tile** function?
It constructs an array by repeating an input array a specified number of times.
57
Define **argmin**.
It returns the index of the minimum value in an array.
58
Define **argmax**.
It returns the index of the maximum value in an array.
59
What does the **where** function do?
It returns the indices of elements in an array that meet a specified condition.
60
True or false: **argmin** can return multiple indices.
TRUE ## Footnote If there are multiple minimum values, argmin returns all their indices.
61
What is the output of **sort([3, 1, 2])**?
[1, 2, 3]
62
What does **repeat(5, 3)** return?
[5, 5, 5]
63
Fill in the blank: **tile([1, 2], 2)** returns _______.
[1, 2, 1, 2]
64
What is the result of **argmin([3, 1, 2])**?
1
65
What does **argmax([3, 1, 2])** return?
0
66
Fill in the blank: **where([1, 2, 3], x => x > 1)** returns _______.
[1, 2]
67
True or false: **sort** modifies the original array.
FALSE ## Footnote The sort function typically returns a new sorted array without altering the original.
68
What is the output of **repeat('a', 4)**?
['a', 'a', 'a', 'a']
69
What does **tile([1], 5)** return?
[1, 1, 1, 1, 1]
70
What is the result of **argmin([5, 2, 8])**?
1
71
What does **argmax([5, 2, 8])** return?
2
72
Fill in the blank: **where([1, 2, 3], x => x < 3)** returns _______.
[0, 1]
73
True or false: **tile** can only repeat one-dimensional arrays.
FALSE ## Footnote Tile can also work with multi-dimensional arrays.
74
What is the output of **sort([5, 3, 4])**?
[3, 4, 5]
75
What does **repeat(0, 5)** return?
[0, 0, 0, 0, 0]
76
What is the result of **where([4, 5, 6], x => x === 5)**?
[1]
77
Fill in the blank: **argmin([10, 20, 5])** returns _______.
2
78
What does **argmax([10, 20, 5])** return?
1