Write a function that creates a matrix of 0s using the list-of-lists strategy.
Your function should:
make_matrix
For example, make_matrix(2, 2)
should return [ [0, 0], [0, 0] ]
. You cannot use any built-in or imported functions besides len()
and range()
.
In [ ]:
In [ ]:
import numpy as np
z1 = np.zeros((5, 10)).tolist()
np.testing.assert_allclose(z1, make_matrix(5, 10))
In [ ]:
z2 = np.zeros((7, 3)).tolist()
np.testing.assert_allclose(z2, make_matrix(7, 3))
Write a function that tests whether every element of a list is even or not. For each individual element of the list, you need to evaluate whether or not that element is even and add the outcome of that test to a list (yep, a list of booleans).
Your function should:
is_even_list
For example, is_even_list([1, 2, 3])
should return [False, True, False]
.
In [ ]:
In [ ]:
import numpy as np
t1 = [1, 2, 3, 4, 5, 6, 7]
a1 = [False, True, False, True, False, True, False]
np.testing.assert_array_equal(a1, is_even_list(t1))
In [ ]:
t2 = [7, 13, 19, 29, 37, 42, 100, 101]
a2 = [False, False, False, False, False, True, True, False]
np.testing.assert_array_equal(a2, is_even_list(t2))