Solution Exercise 7: Stack two numpy matrices vertically
Exercise 7 Stack 2 numpy arrays vertically, i.e. 2 arrays with the same last dimension (same number of columns). Solution import numpy as npA = np.array([[1 , 2], [3 ,…
Python Courses & Exercises with solutions !
Exercise 7 Stack 2 numpy arrays vertically, i.e. 2 arrays with the same last dimension (same number of columns). Solution import numpy as npA = np.array([[1 , 2], [3 ,…
Exercise 6 Stack 2 numpy marices horizontally, i.e. 2 arrays having the same 1st dimension (same number of rows). Solution import numpy as npA = np.array([[1 , 2], [6 ,…
Exercise 5 Convert a numpy binary matrix (containing only '0' and '1') to a numpy boolean matrix (i.e. '1' will be replaced by 'True' and '0' by 'False') Solution import…
Exercise 4 Resume the previous exercise (Exercise3) without using the trace() method. Solution import numpy as npdef matrix_trace(A): n = len(A) # initialization of trace of A trace = 0…
Exercise 3 Write a python function that takes a numpy matrix as a parameter and returns its trace. We recall that the trace of a square matrix A = (ai…
Exercise 2 Write a python program using the numpy library that determines the transpose of the following matrix: A = numpy.array([[1, 2, 3], [4, 5, 6], [7, 8, 9,]]) Solution…
Exercise 1 Using the numpy library, create a 3x3 type matrix made up of the integers 1, 2, 3, ..., 9. Solution import numpy as npM = np.arange(1 , 10).reshape((3,…