1. Introduction to Python: Exercise#
Name:
import numpy as np
Lists and loops#
Create the following lists, possibly in multiple ways.
odd positive integers below 20.
sums from 1 to n, for up to n=10.
prime numbers below n=20.
n=10 random numbers between 0 and k=5.
(use np.random.randint())
np.random.randint?
from two lists of the same length, make a list with the larger of the items at the same position.
from a random list with 7 items, find the median
np.sort?
Arrays and matrices#
an m-by-n matrix with random integers from 0 to k.
# for example
m=3
n=4
from a matrix, make a sub matrix of items in odd rows and even columns.
make a m-by-n matrix with (i,j) component as i/j.
for a n-by-n matrix \(A\), compute the k-th power \(A^k\).