What is numpy or pandas equivalent of the R function sweep()?
numpy
pandas
sweep()
To elaborate: in R lets say we have a coefficient vector (say be
In numpy the concept is called "broadcasting". Example:
import numpy as np x = np.random.random((4, 3)) x * np.array(range(4))[:, np.newaxis] # sweep along the rows x + np.array(range(3))[np.newaxis, :] # sweep along the columns