-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnumpy_exercises.py
More file actions
54 lines (42 loc) · 1.5 KB
/
numpy_exercises.py
File metadata and controls
54 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
def replace_zeros(A, x):
"""
Function modifies the array `A` (of any shape) by replacing all zero elements with `x`.
"""
# Your code here
def centered(A):
"""
Function returns an array made of the array `A` (of any shape) in such a way that from each
of its elements it subtracts the arithmetic mean of all elements of `A`. The array `A` itself
remains unchanged.
"""
# Your code here
def below_diagonal(A):
"""
Function, for a square array `A` (any size greater than 1), creates a one-dimensional array whose
k-th element is the sum of the elements of the k-th column of `A` below the main diagonal.
"""
# Your code here
def checkboard(n):
"""Function creates (and returns) a square array NumPy with alternating ones and zeros of the size
given by the invocation argument `n`, in the form:
>>> checkboard(2)
array([[ 1., 0.],
[ 0., 1.]])
>>> checkboard(3)
array([[ 1., 0., 1.],
[ 0., 1., 0.],
[ 1., 0., 1.]])
>>> checkboard(4)
array([[ 1., 0., 1., 0.],
[ 0., 1., 0., 1.],
[ 1., 0., 1., 0.],
[ 0., 1., 0., 1.]])
>>> checkboard(5)
array([[ 1., 0., 1., 0., 1.],
[ 0., 1., 0., 1., 0.],
[ 1., 0., 1., 0., 1.],
[ 0., 1., 0., 1., 0.],
[ 1., 0., 1., 0., 1.]])
"""
# Your code here