NumPy Flashcards

1
Q

NumPy

A
  • NumPy gives you an enormous range of fast and efficient ways of creating arrays and manipulating numerical data inside them. While a Python list can contain different data types within a single list, all of the elements in a NumPy array should be homogenous. The mathematical operations that are meant to be performed on arrays would be extremely inefficient if the arrays weren’t homogenous.
  • NumPy arrays are faster and more compact than Python lists. An array consumes less memory and is convenient to use. NumPy uses much less memory to store data and it provides a mechanism of specifying the data types. This allows the code to be optimized even further.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Vector

A

This vectorized approach is designed to push the loop into the compiled layer that underlies numPy, leading to much faster execution.

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

Matrix

A
  • An array that has 1-D arrays as its elements is called a 2-D array. These are often used to represent matrix or 2nd order tensors.
  • Ex: arr = np.array([[1, 2, 3], [4, 5, 6]])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

numpy.ndarray

A
  • we can create and array by using array().

* Arr = np.array([1, 2, 3, 4, 5])

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

numpy.argmin/numpy.argmax

A
  • np.argmax() # index where your maximum happens.

* Np.argmax() – index where your minimum happens.

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

Logical Indexing

A
  • ages = np.array([39, 57, 20, 74, 45])
  • ages[[4, 1, 3]] – get elements at indexes 4, 1, 3 (45, 57, 74)
  • ages[:5] – get first 5 elements (returns all)
  • ages[ages >= 40] – get elements where element is greater than or equal to 40
  • ages[[Ture, False, True, False, True]] – get all true elements (39, 20, 45)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Pseudorandom number

A

• pseudo-random numbers are generated by a pre-determined sequence of steps that approximate the patterns of truly random numbers. By setting the seed at a fixed number, we can guarantee repeatable “random” draws.

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