2009/9/16 Ernest Adrogué <[email protected]>: > Hi, > > I have two 1-d arrays (a and b), and I want to create a > third 2-d array, whose rows are of the form a[i]*b: > > c = np.zeros((len(a),b)) > > c[0] = a[0]*b > c[1] = a[1]*b > . > . > . > > Is there an easy way to do this (e.g, without a loop)?
c = a[:,np.newaxis] * b http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
