Array creation Flashcards

1
Q

How do you create an array filled with zeros?

A

Use np.zeros((rows, columns)), where (rows, columns) is a tuple defining the shape of the array. For example, np.zeros((3, 4)) creates a 3x4 array filled with zeros.

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

What does ndarray.ndim represent?

A

It represents the number of axes (dimensions) of the array.

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

What is the difference between np.arange() and np.linspace()?

A

np.arange(start, stop, step) generates values from start to stop with a specified step size. In contrast, np.linspace(start, stop, num) generates num evenly spaced values between start and stop.

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

What data types can be specified when creating an array?

A

You can use standard Python types (like int and float) or NumPy-specific types (like numpy.int32, numpy.float64).

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

How do you calculate sine values for a range of angles?

A

Use np.sin(array_of_angles), where array_of_angles is a NumPy array of angles in radians. For example, np.sin(np.linspace(0, np.pi, 5)) computes the sine values for 5 angles evenly spaced between 0 and
𝜋

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

What is the main object in NumPy?

A

The main object is the ndarray, a homogeneous multidimensional array.

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