NumPy Flashcards

1
Q

What is NumPy and why is it useful?

A
  • A powerful Python library for scientific computing
  • It provides a multidimensional array object, and allows fast operations on arrays including mathematical, logical, array manipulation, sorting and selecting
  • Mathematical operations are up to 50x faster on ndarray objects and require fewer lines of code than Python lists.
  • It contains built-in functions for working with arrays and maths, such as linear algebra and array transformations.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are Numpy arrays?

A

Numpy arrays are the central data structure of the NumPy library. They are a grid of values which may have one or more dimensions:

Vectors: one dimension arrays
Matrices: two-dimensional arrays (2D) represent matrices.
Tensors: higher dimensional arrays

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

NumPy array creation functions

A

range, array, copy, empty, eye, linespace, ones, zeros

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

NumPy conversions

A

astype, mat

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

NumPy manipulations

A

array_split, column_stack, concatenate, hsplit, hstack, reshape, vsplit, vstack

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

NumPy questions

A

all, any, nonzero, where

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

NumPy ordering

A

argmax, argmin, max, min, sort

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

NumPy Operators

A

ndarray.fill, prod, sum

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

NumPy Statistics

A

mean, std, var

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

Get help on Numpy

A

np.lookfor(‘search’)

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

Array shape, dimensions, and size in bytes

A

arr.shape
arr.ndim
arr.itemsize

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

2.Create a 5X2 integer array from a range between 100 to 200, such that the difference between each element is 10

A

arr = np.arange(100,200,10).reshape((5, 2))

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

sample_array = np.array([[11 ,22, 33], [44, 55, 66], [77, 88, 99]])

Return array of items by taking the third column from all rows

A

sample_array[:,2]

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

4.Create a result array by adding the following two NumPy arrays.
# Next, modify the result array by calculating the square of each element.

GIVEN

arrayOne = np.array([[5, 6, 9], [21 ,18, 27]])
arrayTwo = np.array([[15 ,33, 24], [4 ,7, 1]])

A

arrayThree = arrayOne + arrayTwo
arraySquared = arrayThree ** 2

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

Split an array into four equal-sized sub-arrays

arr = np.arange(24).reshape(8,3)

A

new_arr = np.array_split(arr,4)

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

Numpy Where
# b will be all elements of a whenever the condition holds true (i.e only positive elements)
# Otherwise, set it as 0

A

b = np.where(a > 0, a, 0)

17
Q

Sort Numpy Array
- Ascending order
- Descending order

A

arr2 = np.sort(arr)
arr3 = np.sort(arr)[::-1]

18
Q

Add or delete values from an array

A

np.append()
np.delete()

19
Q

What is broadcasting in Numpy?

A

Broadcasting is the name given to the method that NumPy uses to allow array arithmetic between arrays with a different shape or size.