Numpy Flashcards

1
Q

What is NumPy?

A

NumPy is a fundamental package for scientific computing in Python, providing support for arrays, matrices, and a collection of mathematical functions.

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

True or False: NumPy arrays can hold elements of different data types.

A

False

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

What is the main purpose of the NumPy library?

A

The main purpose of NumPy is to provide efficient operations on large arrays and matrices along with a collection of mathematical functions to operate on these arrays.

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

Fill in the blank: The primary data structure in NumPy is the __________.

A

ndarray

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

Which function is used to create a NumPy array from a Python list?

A

np.array()

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

What does the function np.arange() do?

A

np.arange() creates an array with evenly spaced values within a given interval.

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

True or False: NumPy supports multidimensional arrays.

A

True

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

What method would you use to find the shape of a NumPy array?

A

Use the .shape attribute.

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

Multiple Choice: Which of the following is NOT a valid way to create a NumPy array? (a) np.array([1, 2, 3]) (b) np.zeros(3) (c) np.create_array([1, 2, 3])

A

c

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

What does the function np.zeros() return?

A

np.zeros() returns a new array of given shape and type, filled with zeros.

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

Fill in the blank: The function np.linspace(start, stop, num) generates __________ evenly spaced samples.

A

num

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

What is the purpose of the np.reshape() function?

A

np.reshape() changes the shape of an existing array without changing its data.

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

True or False: NumPy provides built-in functions for performing linear algebra operations.

A

True

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

What is the difference between a list and a NumPy array?

A

NumPy arrays are more efficient for numerical operations and support element-wise operations, while lists can hold different data types.

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

Which function is used to compute the mean of a NumPy array?

A

np.mean()

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

Multiple Choice: Which of the following functions can be used to concatenate two NumPy arrays? (a) np.concat() (b) np.append() (c) np.concatenate()

A

c

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

What does the function np.transpose() do?

A

np.transpose() permutes the dimensions of the array, effectively flipping it over its diagonal.

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

Fill in the blank: To sort a NumPy array in place, you can use the method __________.

A

sort()

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

What is broadcasting in NumPy?

A

Broadcasting is a mechanism 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
20
Q

True or False: NumPy can handle missing data in arrays.

A

True

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

What does the function np.unique() do?

A

np.unique() returns the sorted unique elements of an array.

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

What is the purpose of the np.random module?

A

The np.random module is used to generate random numbers and perform random sampling.

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

Multiple Choice: Which of the following is a common use case for NumPy? (a) Web development (b) Data analysis (c) Text processing

A

b

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

What is a masked array in NumPy?

A

A masked array is an array that may have missing or invalid entries, with a mask that indicates which entries are valid.

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

Fill in the blank: The function __________ returns the dot product of two arrays.

26
Q

What is NumPy primarily used for?

A

NumPy is primarily used for numerical computing in Python.

27
Q

True or False: NumPy arrays can only hold elements of the same data type.

28
Q

Fill in the blank: The function to create an array in NumPy is ______.

A

numpy.array

29
Q

What function would you use to generate an array of evenly spaced values?

A

numpy.linspace

30
Q

What is the output of numpy.zeros((2, 3))?

A

A 2x3 array filled with zeros.

31
Q

Multiple Choice: Which of the following functions is used to concatenate two arrays? A) numpy.add B) numpy.concatenate C) numpy.join

A

B) numpy.concatenate

32
Q

What does the method numpy.shape return?

A

It returns the dimensions of the array.

33
Q

True or False: NumPy supports element-wise operations.

34
Q

What is the purpose of numpy.reshape?

A

It changes the shape of an array without changing its data.

35
Q

Fill in the blank: The default data type of a NumPy array is ______.

36
Q

What does the numpy.mean function compute?

A

It computes the average of the array elements.

37
Q

Multiple Choice: Which of the following is NOT a NumPy array method? A) numpy.sum B) numpy.mean C) numpy.sortby

A

C) numpy.sortby

38
Q

What is the result of numpy.array([1, 2, 3]) + numpy.array([4, 5, 6])?

A

An array: [5, 7, 9]

39
Q

True or False: You can use NumPy for linear algebra operations.

40
Q

What function would you use to calculate the standard deviation of an array?

41
Q

Fill in the blank: To create an identity matrix, you would use ______.

42
Q

What does the function numpy.unique do?

A

It finds the unique elements of an array.

43
Q

Multiple Choice: Which function is used to stack arrays in sequence vertically? A) numpy.vstack B) numpy.hstack C) numpy.concat

A

A) numpy.vstack

44
Q

What is the purpose of numpy.transpose?

A

It transposes the dimensions of an array.

45
Q

True or False: NumPy arrays can be multidimensional.

46
Q

What does the method numpy.max return?

A

It returns the maximum value in the array.

47
Q

Fill in the blank: The function used to create a random array is ______.

A

numpy.random.rand

48
Q

What is the output of numpy.arange(5)?

A

An array: [0, 1, 2, 3, 4]

49
Q

Multiple Choice: Which of the following is used to perform matrix multiplication? A) numpy.multiply B) numpy.dot C) numpy.cross

A

B) numpy.dot

50
Q

What does the numpy.where function do?

A

It returns the indices of elements that satisfy a condition.

51
Q

True or False: NumPy can handle missing values in arrays.

52
Q

What function would you use to compute the cumulative sum of an array?

A

numpy.cumsum

53
Q

Basic Array Creation

A
  1. 1D Array: np.array([1, 2, 3])
  2. 2D Array: np.array([[1, 2], [3, 4]])
  3. Zeros Array: np.zeros((3, 4))
  4. Ones Array: np.ones((2, 2))
  5. Identity Matrix: np.eye(3)
  6. Range of Numbers: np.arange(0, 10, 2)
  7. Evenly Spaced Numbers (Linspace): np.linspace(0, 1, 5)
54
Q

Array properties

A
  1. Shape: a.shape
  2. Size (Number of Elements): a.size
  3. Data Type: a.dtype
  4. Number of Dimensions: a.ndim
55
Q

mathematical operations in Arrays

A
  1. Addition: a + b
  2. Subtraction: a - b
  3. Multiplication (Element-wise): a * b
  4. Division (Element-wise): a / b
  5. Matrix Multiplication: np.dot(a, b) or a @ b
  6. Square Root: np.sqrt(a)
  7. Power: np.power(a, 2)
56
Q

Statistical functions in Arrays

A
  1. Sum of All Elements: np.sum(a)
  2. Mean: np.mean(a)
  3. Median: np.median(a)
  4. Standard Deviation: np.std(a)
  5. Variance: np.var(a)
  6. Minimum and Maximum: np.min(a), np.max(a)
  7. Index of Min/Max Element: np.argmin(a), np.argmax(a)
57
Q

Logical Operations in Arrays

A
  1. Element-wise Comparison: a > 5
  2. Check Equality: np.array_equal(a, b)
  3. Any True: np.any(a > 5)
  4. All True: np.all(a > 5)
58
Q

Logical Operations in Arrays

A
  1. Element-wise Comparison: a > 5
  2. Check Equality: np.array_equal(a, b)
  3. Any True: np.any(a > 5)
  4. All True: np.all(a > 5)
59
Q

Indexing and Slicing

A
  1. Access Single Element: a[1] (1D), a[1, 2] (2D)
  2. Slice Array: a[1:4]
  3. Conditional Selection: a[a > 5]
60
Q

Reshaping and Flattening

A
  1. Reshape: a.reshape((2, 3))
  2. Flatten: a.flatten()
61
Q

Random Number Generation using Arrays

A
  1. Random Floats (0-1): np.random.rand(3, 2)
  2. Random Integers: np.random.randint(1, 10, (2, 3))
  3. Normal Distribution: np.random.randn(3, 3)
62
Q

Miscellaneous Operations in Arrays

A
  1. Transpose of Matrix: a.T
  2. Concatenate Arrays: np.concatenate((a, b), axis=0)
  3. Stack Arrays (Vertically): np.vstack((a, b))
  4. Stack Arrays (Horizontally): np.hstack((a, b))
  5. Unique Elements: np.unique(a)
  6. Sorting: np.sort(a)