Advertisement
Korotkodul

A. Долой Python!

Feb 18th, 2025
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def sum_arrays_vectorized(
  4.     lhs: np.ndarray,
  5.     rhs: np.ndarray,
  6. ) -> np.ndarray:
  7.     # ваш код
  8.     if np.shape(lhs) != np.shape(rhs):
  9.         raise ValueError("ShapeMismatchError")
  10.     return lhs + rhs
  11.  
  12.  
  13. def f(x):
  14.     return 3 * x ** 2 + 2 * x + 1
  15.  
  16.  
  17. def compute_poly_vectorized(abscissa: np.ndarray) -> np.ndarray:
  18.     return f(abscissa)
  19.  
  20. def get_mutual_l2_distances_vectorized(
  21.     lhs: np.ndarray,
  22.     rhs: np.ndarray,
  23. ) -> np.ndarray:
  24.     res = np.sqrt(np.sum( (lhs[:, np.newaxis, :] - rhs[np.newaxis, :, :]) ** 2, axis = 2 ))
  25.     return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement