<jupyter_start><jupyter_text>Задача 1<jupyter_code>def jordan_matrix(X: np.ndarray) -> np.ndarray:
    def create_block(x: tuple):
        return np.eye(int(x[1]), k=0) * x[0] + np.eye(int(x[1]), k=1)
    
    fir = create_block(X[0])
    sec = create_block(X[1])
    thi = create_block(X[2])
    
    zero1 = np.zeros((int(X[0][1]), int(X[1][1])))
    zero2 = np.zeros((int(X[0][1]), int(X[2][1])))
    zero3 = np.zeros((int(X[1][1]), int(X[0][1])))
    zero4 = np.zeros((int(X[1][1]), int(X[2][1])))
    zero5 = np.zeros((int(X[2][1]), int(X[0][1])))
    zero6 = np.zeros((int(X[2][1]), int(X[1][1])))
    
    return np.block([
                        [fir, zero1, zero2],
                        [zero3, sec, zero4],
                        [zero5, zero6, thi]
                    ])<jupyter_output><empty_output><jupyter_text>Задача 2<jupyter_code>def complex_expr(A: np.ndarray, B: np.ndarray) -> np.ndarray:
    if A.shape[1] != B.shape[0]:
        return None
    return np.tan(A) @ np.log(np.abs(B))<jupyter_output><empty_output><jupyter_text>Задача 3<jupyter_code>def max_result(X: np.ndarray) -> float:
    a = X.prod(axis=0).min()
    b = X.prod(axis=1).min()
    c = X.min(axis=0).prod()
    d = X.min(axis=1).prod()
    return np.max([a,b,c,d])
X = np.array([[ 1,  2, 13],
              [15,  6,  8],
              [ 7, 18,  9]])

max_result(X)<jupyter_output><empty_output><jupyter_text>Задача 4<jupyter_code>def nearest_value(X: np.ndarray, a: float) -> float:
    X = X.reshape(-1)
    return X[(np.abs(X - a)).argmin()]
nearest_value(X, 7.2)<jupyter_output><empty_output><jupyter_text>Задача 5<jupyter_code>def tensor_mask(X: np.ndarray, mask: np.ndarray) -> np.ndarray:
    return X ^ mask
X = np.array([
              [[ 1, 0, 1],
               [ 1, 1, 1],
               [ 0, 0, 1]],
             
              [[ 1, 1, 1],
               [ 1, 1, 1],
               [ 1, 1, 1]]
            ])
mask = np.array([[1, 1, 0],
                 [1, 1, 0],
                 [1, 1, 0]])
tensor_mask(X, mask)<jupyter_output><empty_output><jupyter_text>Задача 6<jupyter_code>def sort_evens(A: np.ndarray) -> np.ndarray:
    X = A.copy()
    X[X % 2 ==0] = np.sort(X[X % 2 ==0])
    return X
A = np.array([43, 66, 34, 55, 78, 105, 2])
sort_evens(A)<jupyter_output><empty_output><jupyter_text>Задача 7<jupyter_code>def num_sum(A):
    summa = lambda x: sum(list(map(int, list(str(x)))))
    vs = np.vectorize(summa)
    return vs(A)
A = np.array([43, 66, 34, 55, 78, 105, 2])
num_sum(A)<jupyter_output><empty_output><jupyter_text>Задача 8<jupyter_code>def replace_nans(X):
    med = np.nan_to_num(np.nanmedian(X, axis=1))[:, np.newaxis]
    mask = np.isnan(X) * med
    return np.nan_to_num(X) + mask
replace_nans(X)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup