Numpy Flashcards

1
Q

Create a numpy array with numbers from 0-9

A

import numpy as np
array = np.arange(10)

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

Create a 3x3 NumPy array filled with zeros.

A

import numpy as np
array = np.zeros((3, 3))

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

Create a 3x3 NumPy array filled with random values.

A

import numpy as np
array = np.random.rand(3, 3)

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

Create a NumPy array containing all even integers between 0 and 20.

A

import numpy as np
array = np.linspace(0, 1, 10)

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

Create a NumPy array containing 10 equally spaced values between 0 and 1.

A

import numpy as np
array = np.linspace(0, 1, 10)

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

Reshape a 1D NumPy array into a 2D array with 2 rows.

A

import numpy as np
array = np.array([[1, 2, 3], [4, 5, 6]])
transposed_array = array.T

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

Multiply two NumPy arrays element-wise.

A

import numpy as np
array1 = np.array([[1, 2], [3, 4]])
array2 = np.array([[5, 6], [7, 8]])
result = array1 * array2

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

Concatenate two NumPy arrays horizontally.

A

import numpy as np
array1 = np.array([1, 2, 3])
array2 = np.array([4, 5, 6])
concatenated_array = np.concatenate((array1, array2))

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

Perform element-wise comparison between two NumPy arrays.

A

import numpy as np
array1 = np.array([1, 2, 3])
array2 = np.array([2, 2, 3])
comparison = np.equal(array1, array2)

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

Compute the Euclidean distance between two points represented by NumPy arrays.

A

import numpy as np
point1 = np.array([1, 2, 3])
point2 = np.array([4, 5, 6])
euclidean_distance = np.linalg.norm(point1 - point2)

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

Find the unique elements in a NumPy array.

A

import numpy as np
array = np.array([1, 2, 2, 3, 3, 4, 4])
unique_values = np.unique(array)

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

Reverse the order of elements in a NumPy array.

A

import numpy as np
array = np.arange(10)
reversed_array = np.flip(array)

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

Transpose a 2D NumPy array.

A

import numpy as np
array = np.array([[1, 2, 3], [4, 5, 6]])
transposed_array = array.T

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

Compute the exponential of each element in a NumPy array.

A

import numpy as np
array = np.array([1, 2, 3])
exp_array = np.exp(array)

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