On Fri, Apr 17, 2015 at 4:03 PM, Sebastian Berg <sebast...@sipsolutions.net> wrote: > On Fr, 2015-04-17 at 15:18 -0400, josef.p...@gmail.com 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).
Now I'm getting confused I had thought that these two are the same >>> a1[0, 1] = np.array([[100]]) >>> a1[0, 1] = [[100]] but trying it out and from your explanation, they are not I thought Neil's initial use case was that a1[0, 1] = np.outer(5, 1) doesn't work, because of >>> np.outer(5, 1).shape (1, 1) But that works for me. In any case, the thread is getting long, and I explained my perception of use cases for np.outer. Josef > >> >>> 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 >> >> >> >> >> NumPy-Discussion@scipy.org >> >> >> >> >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> >> >> >> >> >> >> >> > >> >> >> >> > >> >> >> >> > _______________________________________________ >> >> >> >> > NumPy-Discussion mailing list >> >> >> >> > NumPy-Discussion@scipy.org >> >> >> >> > http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> >> >> > >> >> >> >> _______________________________________________ >> >> >> >> NumPy-Discussion mailing list >> >> >> >> NumPy-Discussion@scipy.org >> >> >> >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> >> > >> >> >> > >> >> >> > >> >> >> > _______________________________________________ >> >> >> > NumPy-Discussion mailing list >> >> >> > NumPy-Discussion@scipy.org >> >> >> > http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> >> > >> >> >> _______________________________________________ >> >> >> NumPy-Discussion mailing list >> >> >> NumPy-Discussion@scipy.org >> >> >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> > >> >> > >> >> > >> >> > _______________________________________________ >> >> > NumPy-Discussion mailing list >> >> > NumPy-Discussion@scipy.org >> >> > http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> > >> >> _______________________________________________ >> >> NumPy-Discussion mailing list >> >> NumPy-Discussion@scipy.org >> >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >> > >> > >> > _______________________________________________ >> > NumPy-Discussion mailing list >> > NumPy-Discussion@scipy.org >> > http://mail.scipy.org/mailman/listinfo/numpy-discussion >> > >> _______________________________________________ >> NumPy-Discussion mailing list >> NumPy-Discussion@scipy.org >> http://mail.scipy.org/mailman/listinfo/numpy-discussion > > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion