generate functionTue, 28 Feb 2023

X: np.array [num_row, num_column] --- matrix-argument a: float --- meaning for converting odd elements of lines into x Return s: np.array [num_row, num_column*2] --- Matrix, where the lines are flexible lines of the original matrix X with lines, which are their transformations The function takes on the input matrix X dimensions n x m, the number a and Returns the matrix with dimensions n x m*2, the i-th line of which is glued I-th line X with its transformation of its line Transformation (X [I]), written in the reverse order, where the transformation for the number K is defined as: Transformation (k) = a if ind (k) % 2 == 0 else k ** 3 In the implementation of this function, it is necessary to use the functionality of the Numpy package

def task_1(X, a): m = X.shape[1] n = X.shape[0] res = np.zeros(n*m*2).reshape(n, m*2) for i in range(n): res[i, :m] = X[i] res[i, m:] = [x if ind(x)%2==0 else x**3 for x in X[i][::-1]] return res

Questions about programming?Chat with your personal AI assistant