10 NymPy Flashcards

1
Q

What is NumPy?

A

It’s a module in Python that provides optimized functions for numerial computations. It provides a large range of functions for performing scientific computations and handling array data.
It mainly deals with multidimensional array data based on the “numpy.ndarray” object.

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

How are array elements stored in NumPy?

A

as one block with contiguous addresses in memory

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

What’s the difference between how Python stores an element in a list and how NumPy stores an element in an array?

A

In Python, an element in a list is a reference to an object.
In NumPy, an element in an array is a bit pattern of the stored value (not a reference to it but the value itself in form of bits)

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

True or False: Just like lists in Python, an array in NumPy can hold any kind of data type.

A

False. All elements in an NumPy array have the same data type.

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

How are multidimensional arrays stored in NumPy?

A

NumPy flattens all arrays in the background and stores them as 1-dimensional array.

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

What does row-major/column-major order mean, in regards to storing multidimensional arrays in NumPy?

A

row-major order: consecutive elements of a row reside next to each other (after NumPy flattening).
column-major order: consecutive elements of a column reside next to each other (after NumPy flattening).

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

For a 3-dimensional array “my_array” of the shape (3, 4, 5), how can you access the element in the second depth, first row, third column?

A

my_array[1, 0, 2]

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

What is the shape of an array?

A

It defines the multi-dimensionality. It tells you how many dimensions the array has and the length of them.

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

What is the axis of an array?

A

It’s the dimension of the array.

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

Given the provided example, answer the questions below:

[[[1 2 3]
[4 5 6]]
[[9 8 7]
[6 5 4]]]

  1. How many axes does the array have?
  2. What is the array’s shape?
  3. What is the lenth of the first axis?
A
  1. 3 axes
  2. the shape is (2, 2, 3).
  3. the first axis has a length of 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly