10 NymPy Flashcards
What is NumPy?
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 are array elements stored in NumPy?
as one block with contiguous addresses in memory
What’s the difference between how Python stores an element in a list and how NumPy stores an element in an array?
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)
True or False: Just like lists in Python, an array in NumPy can hold any kind of data type.
False. All elements in an NumPy array have the same data type.
How are multidimensional arrays stored in NumPy?
NumPy flattens all arrays in the background and stores them as 1-dimensional array.
What does row-major/column-major order mean, in regards to storing multidimensional arrays in NumPy?
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).
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?
my_array[1, 0, 2]
What is the shape of an array?
It defines the multi-dimensionality. It tells you how many dimensions the array has and the length of them.
What is the axis of an array?
It’s the dimension of the array.
Given the provided example, answer the questions below:
[[[1 2 3]
[4 5 6]]
[[9 8 7]
[6 5 4]]]
- How many axes does the array have?
- What is the array’s shape?
- What is the lenth of the first axis?
- 3 axes
- the shape is (2, 2, 3).
- the first axis has a length of 2