On Fr, 2015-04-17 at 15:18 -0400, [email protected] wrote: > On Fri, Apr 17, 2015 at 2:56 PM, Sebastian Berg <snip> > > Hehe, yeah, that difference. But if you really want that, you can > > usually do a1[0, 1, ...] if you don't mind the ugliness. > > I'm not sure what you mean, although it sounds like a nice trick. > This doesn't work for me >
Oh, mindslip. I thought the problem was that maybe scalar assignment does not remove trailing dimensions. But the actual reason was that you do not have an array on the right hand side. And the assignment code isn't sure if you might want to do object assignment in that case, so it can't do the funny broadcasting of the left hand side (or trailing dimension removing, whichever way around you like to think of it). > >>> a1[0, 1, ...] = [[100]] > Traceback (most recent call last): > File "<pyshell#315>", line 1, in <module> > a1[0, 1, ...] = [[100]] > ValueError: assignment to 0-d array > > >>> np.__version__ > '1.9.2rc1' > >>> a1[0, 1, > > Josef > > > > > > >> Josef > >> > >> > >> > > >> >> > >> >> > >> >> > > >> >> >> I guess we will or would have applications for outer along an axis, > >> >> >> for example if x.shape = (100, 10), then we have > >> >> >> x[:,None, :] * x[:, :, None] (I guess) > >> >> >> Something like this shows up reasonably often in econometrics as > >> >> >> "Outer Product". However in most cases we can avoid constructing this > >> >> >> matrix and get the final results in a more memory efficient or faster > >> >> >> way. > >> >> >> (example an array of covariance matrices) > >> >> > > >> >> > > >> >> > Not sure I see this. outer(a, b) should return something that has > >> >> > shape: > >> >> > (a.shape + b.shape). If you're doing it "along an axis", you mean > >> >> > you're > >> >> > reshuffling the resulting shape vector? > >> >> > >> >> No I'm not reshaping the full tensor product. > >> >> > >> >> It's a vectorized version of looping over independent outer products > >> >> > >> >> np.array([outer(xi, yi) for xi,yi in zip(x, y)]) > >> >> (which I would never use with outer) > >> >> > >> >> but I have code that works similar for a reduce (or reduce_at) loop over > >> >> this. > >> >> > >> >> Josef > >> >> > >> >> > >> >> >> > >> >> >> > >> >> >> Josef > >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> >> > > >> >> >> > - Sebastian > >> >> >> > > >> >> >> > > >> >> >> >> Best, > >> >> >> >> > >> >> >> >> Matthew > >> >> >> >> _______________________________________________ > >> >> >> >> NumPy-Discussion mailing list > >> >> >> >> [email protected] > >> >> >> >> http://mail.scipy.org/mailman/listinfo/numpy-discussion > >> >> >> >> > >> >> >> > > >> >> >> > > >> >> >> > _______________________________________________ > >> >> >> > NumPy-Discussion mailing list > >> >> >> > [email protected] > >> >> >> > http://mail.scipy.org/mailman/listinfo/numpy-discussion > >> >> >> > > >> >> >> _______________________________________________ > >> >> >> NumPy-Discussion mailing list > >> >> >> [email protected] > >> >> >> http://mail.scipy.org/mailman/listinfo/numpy-discussion > >> >> > > >> >> > > >> >> > > >> >> > _______________________________________________ > >> >> > NumPy-Discussion mailing list > >> >> > [email protected] > >> >> > http://mail.scipy.org/mailman/listinfo/numpy-discussion > >> >> > > >> >> _______________________________________________ > >> >> NumPy-Discussion mailing list > >> >> [email protected] > >> >> http://mail.scipy.org/mailman/listinfo/numpy-discussion > >> > > >> > > >> > > >> > _______________________________________________ > >> > NumPy-Discussion mailing list > >> > [email protected] > >> > http://mail.scipy.org/mailman/listinfo/numpy-discussion > >> > > >> _______________________________________________ > >> NumPy-Discussion mailing list > >> [email protected] > >> http://mail.scipy.org/mailman/listinfo/numpy-discussion > > > > > > _______________________________________________ > > NumPy-Discussion mailing list > > [email protected] > > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > > _______________________________________________ > NumPy-Discussion mailing list > [email protected] > http://mail.scipy.org/mailman/listinfo/numpy-discussion
signature.asc
Description: This is a digitally signed message part
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
