« first day (2338 days earlier)      last day (880 days later) » 

12:13 AM
@flawr It's the operations with them that are scary :-)
Yeah, I'm still in the "resisting" phase with Git...
 
If you want scary, here's scary:
In [295]: import numpy as np
     ...:
     ...: arr = np.zeros((3, 3))
     ...: np.einsum('ii->i', arr)[:] = 42
     ...: arr
Out[295]:
array([[42.,  0.,  0.],
       [ 0., 42.,  0.],
       [ 0.,  0., 42.]])
I learned that a few days ago
 
Yeah, Einstein summation was more or less what I was thinking of
 
In einsum 'ii -> i' is the same as diag(), except the former returns a writeable view whereas the latter does not
@LuisMendo I'd expect that you don't see them that often, partly because they are not particularly fast
 
einsum looks a lot like code golfing then
 
It does. Einstein convention itself was code golf.
 
12:17 AM
Yeah, common subindices imply sum. Or something like that
 
It's originally more specific: a covariant and a contravariant index together imply a sum. Because those are the kinds that contract in general relativity.
so basically M_{ab} x^a y^b
 
BRB googling covariant and contravariant
 
for the record this is what you'd do without einsum:
In [301]: arr = np.zeros((3, 3))
     ...: d = np.diag(arr)
     ...: d.flags['WRITEABLE'] = True
     ...: d[:] = 42
     ...: arr
Out[301]:
array([[42.,  0.,  0.],
       [ 0., 42.,  0.],
       [ 0.,  0., 42.]])
@LuisMendo oh, no, don't do that, it's past 1 AM! :D
 
:-D
 
so what I'd actually do is arr[range(n), range(n)] = 42
 
12:20 AM
which is confusing for a long-time user of Matlab, where that would imply filling the full array
 
Well, yeah, but that's fundamental numpy. Pretty much the first thing you find when you dip in a toe.
 
I know, I know :-)
 
Ugh. Matlab doc is really the best
So... bed time. Good night!
 
Same. Night.
 
 
8 hours later…
7:58 AM
@LuisMendo @AndrasDeak einops.rocks
I know I linked it before but if you love einsum you'll love this stuff!
basically it also lets you do things like c h w -> (c h) w (Let's say we have an image with c channels, we can concatenate all the channels into the height dimension to get a B/W image the channels.)
and much more
 
@flawr meh
@flawr I can do that with reshape
 
@AndrasDeak the point is that you can do all these operations in one go, let's say you want to do a matrix multiplication afterwards, you could do that in one einops operation
ok that was a bad example
but I think the point is that as soon as you do a transformation that has to rearrange data and doesn't just modify the strides, you have an advantage with using stuff like this
cause you don't have to execut multiple calls from python
 
9:01 AM
@flawr I get it. I just don't like the kind of self-hype einops does.
 
9:15 AM
ok I understand, but I do really like the gif:)
 
Sam
9:35 AM
@AnderBiguri I am good thank you! It's been a while :)
 
10:04 AM
@flawr scary :-D
 
10:20 AM
@flawr lies
 
 
5 hours later…
3:18 PM
@Adriaan 1 Hz = 2π rad/s. So, I think this question is okay!
 
3:40 PM
True
 
 
7 hours later…
10:36 PM
I think I'm completely overthinking this
Let's say we have some numpy array with a.shape = (100, 3), as well as some indices e.g. ind = [3, 14, 15, 92] Now I'd like to partition a by extracting the rows indicated by the ind and all the other rows. So x = a[ind, :] and y = a[???, :]. Is there a neat way to do this?
I was thinking of making a mask for logical indexing, or alternatively do something like yind = list(set(range(a.shape[0]))-set(ind)); y = a[yind, :]
 
a[np.in1d(range(a.shape[0]), ind, invert=True), :] works, but no idea how idiomatic this is
Now that Andras is not here: Matlab's a(~ismember(1:end, ind), :) is way better
 
10:58 PM
>:|
@flawr I'd use a mask
np.isin(np.arange(a.shape[0]), ind)
so what Luis said, but I think isin is preferred these days
and you'll need the mask itself to negate it of course
 
@LuisMendo @AndrasDeak thanks for the suggestions!
yeah I went with a mask for now
 
@LuisMendo note that you could do a[~np.isin(range(a.shape[0]), ind), :] which is barely worse. 1:end working like that is still crazy :P
 
@AndrasDeak isin's name at least sounds more reasonable than in1d
Yeah, end working like that in indices is kinda unexpected. But very expressive, I love it
 
@flawr oooh I've got it
 
got what?
 
11:12 PM
In [318]: ind = [3, 14, 15]
     ...: complement = np.setdiff1d(range(20), ind)

In [319]: complement
Out[319]: array([ 0,  1,  2,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 16, 17, 18, 19])
Luis' in1d remark made it click
 
@AndrasDeak that's what I wrote in more words:)
I do love the < >= - + etc for sets:)
D: wait they didn't define + for sets???? D:
 
@LuisMendo I just wondered why you suddenly started using :) instead of :-) for smileys
@AndrasDeak ok fair. but too bad it's not the same operator as for lsits
 
I think + and - should go together, whereas for sets & and | go together
it's not just sets though, by the way
In [323]: {1: 2, 3: 4}.keys() | {5: 6}
Out[323]: {1, 3, 5}
 
oh you can even | dicts directly
 
11:19 PM
yup
 
@AndrasDeak but OR-ing a dict-keys object with a dict tastes a little bit weird
 
@flawr yeah, the assumption is that dict keys are set-like, and that iterating a dict iterates over keys
so it sort of makes sense, but it does look weird
and it's probably rarely useful
 
too bad, symmetric differences don't work for dicts:)
would have been fun
 
not even & works for dicts
 
hm
 
11:22 PM
but you can use a collections.Counter which is a multiset if you squint a bit
>>> Counter({2: 3, 4: 6}) - Counter({4: 2})
Counter({2: 3, 4: 4})
 

« first day (2338 days earlier)      last day (880 days later) »