text stringlengths 0 2.87M |
|---|
import numpy as np |
def squared_pairwise_distances_vectorized(p: np.ndarray, q: np.ndarray) -> np.ndarray: |
""" |
Compute the squared pairwise distances between two sets of points p and q. |
Parameters |
---------- |
p : np.ndarray |
The first set of points. Shape is (n, d). |
q : np.ndarray |
The second set of points. Shape is (m, d). |
Returns |
------- |
np.ndarray |
The squared pairwise distances. Shape is (n, m). |
""" |
return (p**2).sum(axis=1, keepdims=True) + (q**2).sum(axis=1) - 2 * p @ q.T |
def squared_pairwise_distances_naive(a: np.ndarray, b: np.ndarray) -> np.ndarray: |
""" |
This function should do the same as squared_pairwise_distances_vectorized, |
but without using any vectorized operations. It is provided for |
comparison purposes only. |
""" |
distances = np.zeros((a.shape[0], b.shape[0])) |
[...] |
return distances |
def main() -> None: |
p = np.random.rand(7, 2) |
q = np.random.rand(5, 2) |
distances_vectorized = squared_pairwise_distances_vectorized(p, q) |
distances_naive = squared_pairwise_distances_naive(p, q) |
assert np.allclose(distances_vectorized, distances_naive) |
if __name__ == "__main__": |
main()<user><kinrel>Here is your completed code: |
``` |
import numpy as np |
def squared_pairwise_distances_vectorized(p: np.ndarray, q: np.ndarray) -> np.ndarray: |
""" |
Compute the squared pairwise distances between two sets of points p and q. |
Parameters |
---------- |
p : np.ndarray |
The first set of points. Shape is (n, d). |
q : np.ndarray |
The second set of points. Shape is (m, d). |
Returns |
------- |
np.ndarray |
The squared pairwise distances. Shape is (n, m). |
""" |
return (p**2).sum(axis=1, keepdims=True) + (q**2).sum(axis=1) - 2 * p @ q.T |
def squared_pairwise_distances_naive(a: np.ndarray, b: np.ndarray) -> np.ndarray: |
""" |
This function should do the same as squared_pairwise_distances_vectorized, |
but without using any vectorized operations. It is provided for |
comparison purposes only. |
""" |
distances = np.zeros((a.shape[0], b.shape[0])) |
for i in range(a.shape[0]): |
f or j in range(b.shape[0]): |
distances[i, j] = np.sum((a[i] - b[j])**2) |
return distances |
def main() -> None: |
p = np.random.rand(7, 2) |
q = np.random.rand(5, 2) |
distances_vectorized = squared_pairwise_distances_vectorized(p, q) |
distances_naive = squared_pairwise_distances_naive(p, q) |
assert np.allclose(distances_vectorized, distances_naive) |
# added print statement to indicate successful run of the test |
print("Success!") |
if __name__ == "__main__": |
main() |
```<kinrel><user>¿Cuantos pares son tres botas?<user><kinrel>Con 3 botas solo puedes llegar a tener un solo par, aunque se pudiera decir que 3 botas son 1.5 pares ya que 3 botas dividido por 2 botas por par es 1.5<kinrel><user>My bicycle tire has a puncture and while I have a pump with me, I don't have a patch repair k... |
Material: necessitaràs fusta o altre material per a la taula, com ara metall o plàstic, segons les teves preferències. També pots necessitar eines com ara una serra de calar, un martell, claus, cola, etc... |
Disseny: Decideix les mides que vols que tingui la teva taula i dibuixa un esborrany per tenir una idea clara de com la vols construir. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.