« first day (2357 days earlier)      last day (2577 days later) » 

wim
12:01 AM
damnit, the stride thing is tantalisingly close
but I don't think it's going to work
 
@AndrasDeak He'll beat you with a cycle chain and repeat until you accumulate a starmap of bruises.
 
:|
I'll just dropwhile he's not looking
 
wim
>>> np.linspace(0, 54, 4).astype(int)
array([ 0, 18, 36, 54])
ooh
could be helpful
 
seriously? boo itertools, but numpy is OK?
 
wim
hahah, yeah
 
12:06 AM
ridiculous
 
wim
you said it ... but you said "boo" before it, so I'll let it slide
 
Surely you'd just use np.split(a, n) if you were going to use numpy?
 
wim
I tried it
it doesn't work
ValueError: sadface.jpg
 
In [8]: def wimfun(t,n):
   ...:     N = len(t)
   ...:     n0,rem = divmod(N,n)
   ...:     sublens = [n0+1]*rem + [n0]*(n-rem)
   ...:     inds = (sum(sublens[:k]) for k in range(len(sublens)))
   ...:     return [t[i0:i0+width] for i0,width in zip(inds,sublens)]
   ...:

In [9]: wimfun(t,n)
Out[9]:
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
 [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27],
 [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],
 [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53]]
 
wim
12:09 AM
np.array_split(L, 4) that's it
 
I should've written the function to be an acrostic, with the first letters spelling out itertools
 
wim
claps thank you zero
oh, numpy! <3 <3
is there anything you can't do
 
DSM
Handle ragged arrays cleanly.
 
nature abhors ragged arrays
 
Pfft, ragged arrays. They oughtta shape up.
 
wim
12:12 AM
LOL
and by LOL, I mean the corners of my mouth turned up slightly in recognition of your pun
 
on a wim scale that's an appreciation level of "you're not such a huge turd after all"
 
wim
just a small turd
 
yup
 
wim
but srsly, my upvote/downvote ratio was something like 10:1
last time I checked
other guys in here are way meaner
 
like me:D
all time
843 up
2,193 down
 
wim
12:18 AM
thats harsh
do you actively go out searching for crap?
or you just don't bother to upvote good stuff
 
I mostly look at questions, new ones
 
can't decide whether todayspetpics is more reminiscent of "today skeptics" or "to dyspeptics"
 
DSM
@ZeroPiraeus: is it too late to propose "toady septics"?
 
+1 for correct circumflex use. Also :-D
 
wim
12:28 AM
unfortunately user248237dfsf was last seen in Feb 2015 so it may not help him.
cool username though
"I care enough to change the autogenerated username, but not enough to delete characters in that widget"
"also I'm a qwerty user and browse with mouse in the right hand"
 
You hope it's a mouse.
 
let me just downvote that user who posts a numpy answer to a native python question
And numpy.array_split() is even more adequate because it roughly splits. — Yariv Mar 9 '13 at 10:38
 
DSM
@Brandin: where did your expected value come from? It seemed unlikely to me that Python would behave differently than the others here, and a quick check with pypy, compiled Python, C++, and Julia all agree with the CPython result.
 
12:43 AM
*compylethon
I accept if it won't catch on
rhubarb
 
DSM
Originally I thought the OP was just looking for a version of combinations (from the 28) but I can't quite figure out what 16*28 is meant to be.
 
It's always possible that OP is confused.
 
DSM
Maybe [list(zip(p, c)) for p in product(bases, repeat=2) for c in combinations(range(8), 2)]? That'll have length 448, but it feels quite artificial.
Yeah, I'm pretty sure that's what he's after.
 
DSM
1:42 AM
@Zero: I couldn't resist.. always a sucker for itertools.
 
Good job @wim isn't here …
 
DSM
:-P If he can't handle the 'toolz groove, that's his problem.
 
The perfect question is one that allows an answer incorporating the itertools/collections/functools trifecta, of course.
 
 
5 hours later…
6:31 AM
cbg, guys!
 
@DSM For CPython I got a slightly smaller value for some reason. I expected 9999818.4485011194 because that is what I got for the C/C++ version. Tcl gives 9999818.44850112 which is just a rounded off version of the same.
 
6:50 AM
Sup people
Have a nice day!
 
guys, I had a question. Can we put the element containing the start anchor somewhere between in the regex? Like
(something)(^start element)(something else)
to match
start element something something else
 
i suppose this is somewhat achievable with m flag
What are you trying to do exactly?
Positive or negative lookaheads may be more fitting
 
I am trying to match say abc xyz pqrs but dont want to put the (^abc) in the starting, but in the middle
 
why?
I mean putting ^ anchor in a middle of a regex is definetely a bad idea
try (?<=a)bor (?<!a)b
 
7:07 AM
this is because i am converting a search rule to regex, and I am breaking the work into modules. Somehow, it is not possible to put the start anchor element in the beginning, so i was wondering if it can be pt somewhre else
 
show me a solid example
 
i tried here, clearly this does not work
 
(?<=^hello)world something
 
7:26 AM
cbg
 
print('cbg folks')
 
@ArishPyne but is it working? I think its not working - world something(?<=^hello) does not match helloworld something. right?
 
It seems like you do not understand regex lookaheads
(?<=^hello)world something - matches `world something` if it is preceded by `hello`
Is this what you're trying to achieve?
 
@ArishPyne but I already know that we can use ^ for start of line. And my question is related to start of line only. I know that my line starts with a particular string and my question is that, can we write the regex for this somewhere in the middle of the entire regex. am i making sense?
 
7:47 AM
not quite
Using anchors in regex means that this regex wil lbe applied line-by-line
I can't quite understand why do you need the start of theline anchor in the middle
Are you trying to match the line only if previous line contained something?
like
match line abc only if previous line was xyz?
i.e.
match
s
 
no, there is no such condition
@ArishPyne this is because i am automatically generating regexes for the various parts of the line, and its somehow not possible for me to keep the regex elements in order, so I thought of using the fact that regex is modular, so lets just put the regex code for the various parts in any order. Note, that I am dealing with only only one line at any given time.
 
is there a concrete example?
 
sure
LINE_CONTAINS phrase one BEFORE {phrase2 AND phrase3} AND LINE_STARTSWITH However we
its regex would be re.search(^However we(?=phrase one.*?(phrase2|phrase3)))
but since i am parsing the various elements seprarately (code is here), its not pssible to make the entire regex properly in order, so i am breaking it into parts
for a clearer description of the problem, I have written it here
 
I've bookmarked it, will take a look later
 
sure
 
8:12 AM
cbg
 
8:26 AM
cbg
 
8:36 AM
m=int(input())
mylist=[]
for i in range(m):
mylist.append(input())
print (mylist.reverse())
why i am getting NONE. is something wrong in code
 
@sasi list.reverse() reverses the list in place, returning None
Either use reversed(), or print the list after a call to mylist.reverse().
Also note that reversed() returns an iterator, not a list.
 
ok thanks. i will try and get back.
 
@sasi considering Ilja hint, you can do just:
mylist.reverse()
print(mylist)
 
9:15 AM
anyone know what the fastest way to extract a bit value from a byte in python would be?
my current way of doing it is like so:

`word >> (start_bit) & (2 << (field_size - 1)) - 1`
actually I'm not trying to extract a single bit (thought it might be) it's a subset of bits from the byte (word in the example above)
 
user6845426
cbg o/
 
@marxin. ya i got it.
 
I'm hoping to speed up my code, and this appears to be the area where the most time is spent
 
I don't know if its faster but maybe try word & (1 << bit_number) > 0?
 
wouldn't that return a boolean?
 
9:29 AM
0 if its 0, > 0 if its 1
it does AND, for example 00010010 & 00010000, which gives 00010000 as output therefore it would return 16
 
word = int('11001010', 2)

word & (1 << 5) > 0
Out[2]: False
oh wait... you're just finding a single bit
 
oh, yeah, greater than 0 is at the end ;) but thats just to say if its 1 or 0
yes
 
I meant to edit my first statement, but didn't get to it til it was too late
I'm hoping to get possibly multiple bits from a single word
 
did you try binascii module?
it guess you tried and its too slow?
 
so for example '11001010' I would want to extract out the 1100
the values that I'm actually working with are already integers
so binascii doesn't do what I think I need this to do
but I might be wrong
 
9:34 AM
yeah youre right, I meant something else, sry ;d
 
it's all good
 
yeah, I remember now, just bin() function
 
well I'm actually taking a binary file, and parsing it. I get an integer, but that integer represents multiple things (fields)
I'm trying to quickly parse that field so I can further parse the file accordingly
 
In [27]: bin(162)
Out[27]: '0b10100010'
 
I'm talking 1000's of operations and the bottleneck is the extracting out the values
 
9:36 AM
then you can slice output to get range?
yeah I understand
Im wondering if you need to create integers from them then
not just working on binary data in first place
 
cabbage
 
I would think that converting to bin, then slicing and then converting back to int would be too expensive
@marxin I'm talking about binary data like b'\x00\x01\x02' and so forth
 
Yeah I know, I just dont understand why you convert binary to integers if you then need to get binary representation again
 
I don't need binary representation
I have a file that has a bunch of packets within in
I'm trying to extract out the packets from them
since each packet is potentially a different size, I'm trying to get the type of packet, and then the size and then parsing the packet accordingly
so conversion is from binary to a integer
then extract from integer a subset of values
 
if you know which bytes you need to extract
then you can just do "variable & 15" for example, to get first three bytes
 
9:46 AM
but what if I want the last 3 bits
or some middle bits?
 
that should be possible as well, just get a number which represents 111000000000 in binary
my_variable & 3758096384 ?
 
that's basically what this does:

`word >> (start_bit) & (2 << (field_size - 1)) - 1`
 
try with dis module and see if there is any performance gain using constant
 
I'm not sure how the dis module is going to help me here
 
In [4]: def get_size(val):
return val & 3758096384
...:

In [5]: dis.dis(get_size)
2 0 LOAD_FAST 0 (val)
3 LOAD_CONST 1 (3758096384)
6 BINARY_AND
7 RETURN_VALUE
with this approach can be difficult to get anything better, its already doing almost nothing
 
10:00 AM
def my_func(word, start_bit, size):
    return word >> (start_bit) & (2 << (size - 1)) - 1


import dis

dis.dis(my_func)
  2           0 LOAD_FAST                0 (word)
              3 LOAD_FAST                1 (start_bit)
              6 BINARY_RSHIFT
              7 LOAD_CONST               1 (2)
             10 LOAD_FAST                2 (size)
             13 LOAD_CONST               2 (1)
             16 BINARY_SUBTRACT
             17 BINARY_LSHIFT
             18 LOAD_CONST               2 (1)
I see now what you mean
 
Cabbage
Why the parentheses around (start_bit) ?
 
but I would try to extract values you need from packet header without converting anything to integer, I might be wrong ofc, its difficult to say since I dont know what exactly you do
I assume packet header structure is known
 
cbg
 
And you can simplify the second part:
word = 0b000110100000
start_bit, field_size = 5, 4
result = (word >> start_bit) & ((1 << field_size) - 1)
print(bin(result))
#output
0b1101
 
user6845426
cbg
 
10:03 AM
@PM2Ring I think originally I had a different operation in there
i.e (start_bit - 32)
 
That expression can be written like this, but I think it's a good idea to use the extra parentheses to explicitly show the grouping.
result = word >> start_bit & (1 << field_size) - 1
 
but that changed
 
@KronoS Ah, ok.
 
@marxin yes it is
@marxin I'm extracting values from the file using the struct module, but that only goes down to the int size
 
@AndrasDeak FWIW, I saw Wim discussing splitting a list into uneven parts, so I wrote an answer
 
10:05 AM
what is this cbg?
@PM2Ring that does reduce the number of operations required
def my_func(word, start_bit, size):
    return word >> start_bit & (1 << size) - 1


dis.dis(my_func)
  2           0 LOAD_FAST                0 (word)
              3 LOAD_FAST                1 (start_bit)
              6 BINARY_RSHIFT
              7 LOAD_CONST               1 (1)
             10 LOAD_FAST                2 (size)
             13 BINARY_LSHIFT
             14 LOAD_CONST               1 (1)
             17 BINARY_SUBTRACT
             18 BINARY_AND
             19 RETURN_VALUE
 
@KronoS There is a 3rd-party module for doing bitwise stuff, but I've never used it, so I don't know how efficient it is. pypi.python.org/pypi/bitarray
@KronoS In the room rules, you will find this: "Incidentally, if you've just been greeted with the word "cbg" or "cabbage" then you may want to have a look here...
 
I'll have to look into that
@PM2Ring thanks. I read through the room rules, but must've missed that
 
@PM2Ring That module has some questionable practices, such as using uninitialized (indeterminate) memory areas. May contain UB.
 
@KronoS I assume it's much faster than doing intensive bitwise stuff in pure Python. All arithmetic in pure Python is relatively slow because it uses immutable Python integer objects rather than native machine integers.
 
@PM2Ring I'm sad it's not recursive ;)
 
10:11 AM
@IljaEverilä Oh dear! Antti would not be pleased. That's a rookie C error.
 
We've been having a side channel discussion about it just now...
 
ha! I think I can use c_types
 
@AndrasDeak :) I do like writing recursive generators; OTOH, I normally try to avoid recursion in Python when it's not appropriate for the problem domain.
 
But that particular UB candidate can be avoided by not using the bitarray(123) form of initialization, which would simply malloc space for 123 bits or more.
 
@KronoS Yes. ctypes is great, in terms of speed & reliability, although it can make the code a little messy.
 
10:15 AM
> int, long
> Create bitarray of length given by the integer. The initial values
> in the array are random, because only the memory allocated.
"random"
 
@IljaEverilä I must admit that we use to use uninitialised memory fairly frequently in Ancient Times on more primitive architectures. But even then, you read from such memory at your peril. :) But it was handy for stuff like recovering data after the machine crashed and rebooted. :)
 
Yeah, C and UB is a complex subject.
And an allocated area from malloc is just indeterminate, but then again you cannot do much with indeterminate values without invoking UB.
And then again, Python itself at least used to use -fwrapv. Is that still true?
 
@IljaEverilä No idea. But I bet Martijn knows.
 
The point being that UB might not be undefined in some cases, with a suitable system and compiler mix :P
 
$ grep -C2 -i wrap ~/cpython/cpython3.6/Makefile

# Compiler options
OPT=		-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
BASECFLAGS=	 -Wno-unused-result -Wsign-compare
BASECPPFLAGS=
that came shipped with cpython3.6 from github
@IljaEverilä I think @Antti would say that it's still UB, and slap you with a trout :P
I pinged him, run for your life
 
10:32 AM
Nah, he'd argue that using -fwrapv kills some optimization possibilities, but -fwrapv defines signed integer overflow's behaviour. Makes it less portable though, and not quite C.
@AndrasDeak Luckily we're at opposite ends of Oulu these days :D
 
@IljaEverilä I am in Porvoo atm.
 
Less reason for me to run, then
 
tomorrow I will pass past your workplace methinks at 7 pmish
 
10:58 AM
Hmm
Coffee?
 
pass... past... :d
 
Oh, pm
 
and pm... :D
@AndrasDeak and yes, it is still UB as per C. but not UB as per GCC with -fwrapv.
@AndrasDeak damn, actually that is not correct!
one needs to have fwrapv also without OPT.
actually the optimizations are explained on GCC man pages for -fstrict-overflow
 
11:13 AM
Oh, @Antti has still not hit 50k
I already hit 25k
 
@BhargavRao ...
 
!?!
 
Mar 6 at 11:52, by Bhargav Rao
I once managed to upvote my answer, and later realized that I was running a sock account :O
 
* F I G H T ! *
 
@BhargavRao ^is it because of this :d
 
11:15 AM
hehe
*flagging*
 
@AnttiHaapala Yussss
 
@AndrasDeak declined
 
11:16 AM
You want some of those socks to get to 50k, @Antti?
 
@BhargavRao Congratulations! But I bet you already had access to Site Analytics. :)
 
@PM2Ring Thanks and same to you!
 
Thanks!
 
Yep, I got that when I became a mod.
Totally useless priv though :D
 
Agreed.
 
11:18 AM
I've never used it.
 
It's even lamer than the 5k privilege "approve tag wiki edits"
 
Lol, yep.
 
this is a cool system on Finnish railways (such systems exist elsewhere of course but...): the rolling stock - each single car has RFID tags attached on both sides and both ends. These are being read when the car passes at even 180 km/h and stored into database... the same system also measures axle temperatures and in case of an impeding bearing failure, the system will proactively warn about it...
 
S.M.A.R.Trains
Here we have trains that roll on wheels
 
11:34 AM
Clever OP... deleted their old question and recreated it word for word, probably because they were unhappy with my comments – mainly requiring mcve and explaining that Alembic might not catch the PK change and that they would have to manually intervene: stackoverflow.com/questions/43116345/…
It's in the bloody docs even.
 
I sugggest reproducing your comments
 
I suggest backing off for a bit
 
because this is the other post stackoverflow.com/questions/43110895/…
 
ah, different user
what are the odds :P
 
11:46 AM
@BhargavRao Added the same info about how alembic works as the last time. Different user or not.
It is the same question after all.
 
I think he means that mod action is being taken
 
Ah, whoosh
 
hmm
what's the tool to use to copy a disk image into a partition but not writing zeroes
 
dd?
dd if=... of=...
just not from /dev/zero?
 
11:57 AM
or what do you mean by "not writing zeroes"? Do you only want to copy the ones from your data?:P
come to think of it, that's a great way to save space
@IljaEverilä don't expect a response soon :P
 
# dd if=/dev/zero of=foo
^C
du foo
82088   foo
should be close to 0 instead...
   sparse try to seek rather than write the output for NUL input blocks
hmm
# dd if=/dev/zero of=foo conv=sparse
^C3207363+0 records in
3207362+0 records out
1642169344 bytes (1.6 GB, 1.5 GiB) copied, 3.92644 s, 418 MB/s
# du foo
0       foo
 
what does that mean?
 
@AndrasDeak the file that contains 1.6G zero bytes consumes 0 blocks on disk
 
DSM
@Brandin: so far I've been unable to reproduce your expected result on any language on my system, though, so I'm starting to wonder if it's a libmath thing.
 
@AnttiHaapala oh, I missed the du. That's...weird.
 
12:09 PM
@AndrasDeak WEIRD?
you call Unix weird?
 
@AnttiHaapala Nice. My dd doesn't know about conv=sparse. Or at least, it's not in the man page.
 
@PM2Ring surprised people: _______________
 
@AndrasDeak Sparse files have been around for ages. I but I didn't know dd could do them.
 
@PM2Ring dd can do them, but
 
12:11 PM
the point is that it can convert from zeros into holes
 
or it's another sock account by OP
 
@AnttiHaapala Stop knocking my kerosene-powered OS. :)
 
@BhargavRao what do you think? -----^
@AnttiHaapala ballsy
 
@AndrasDeak antti should stop knocking PM's kerosene powered OS
 
lol:D
thanks for the authoritative input
 
12:12 PM
Love the assertive tone: " Tell me how to me replace primary key in columns in one table"
 
we're talking about an OP whose entire 60 rep was from a sock account
 
@AndrasDeak So it turns out "they" did respond...
 
12:33 PM
There goes Oscar.
 
poor Academy
 
12:57 PM
Just in case I'm reinventing the wheel: is there a itertools/functools function that "counts"/groups elements in a set? IE: "abaccbb" -> {a:2, b:3, c:2}
 
collections.Counter
 
facepalms
 
from collections import Counter
print(Counter("abaccbb"))
#output
Counter({'b': 3, 'a': 2, 'c': 2})
@paul23 Who would've thought that there'd be a counter class named Counter? :)
 
Took me a while to find Counter my first time because I kept googling for "histogram"
 
Yeah thanks used it often already
 
1:01 PM
I noticed in the transcript that someone had trouble loading a list of 5000000 primes. I wonder how big those primes are, or at least, how dense the list is. If it's literally a table of the first 5000000 primes (i.e., the primes upto and including 86028121) that can be compactly stored in an array of 2867605 bytes.
 
Just forgot it had such "powerful" constructors
 
OTOH, my technique of doing that does involve bit manipulations, so it's not particularly fast in Python, but it's pretty cool in C.
 
In the counterfactual, I wonder what possible use one could get out of a sequence of five million primes that aren't the first five million primes in order
"I need these five million Mersenne primes, because I'm very very serious about random number generation"
 
@Kevin I haven't used Counter very much. It got back-ported to 2.7, but not to 2.6. There is a "recipe" called Counter_25.py, but I kept forgetting that I'd downloaded it, and just rolled my own solutions, either using a defaultdict, or a plain dict. :)
 
Scientific computation for mathematicians?
 
1:06 PM
Considering the 49th Mersenne prime is 2^74,207,28 - 1, that would be a pretty big list.
 
@PM2Ring Did you imply that you use python 2.6?
 
How OP even found the remaining 49,999,951 primes in the list would probably be quite a story
 
@Kevin He may be wanting to test factorizing algorithms. So being able to quickly generate a big number with only 2 or 3 prime factors is useful.
@paul23 I did. I upgraded to Python 3.6 alpha last May. But still use 2.6 when I need to test Python 2 code for an SO answer.
 
Agreed, but I think a list of, idk, a thousand big primes would suffice for testing purposes
That gives you 1000^2 possible nonprimes to factor, which is decent
 
May 12 '16 at 12:49, by PM 2Ring
Ok. I finally made the big jump from Python 2.6 to Python 3.6, which I compiled myself. With lots of help from Antti. :
 
1:10 PM
Compiled yourself? Why would you hurt yourself so much.... shakes head
 
Thus marked the beginning of a new Age.
 
@Kevin Yeah, it's a bit beyond what my PCG Mersenne code can do. :)
 
Hmm, maybe try tightening the speedup loop? That always makes my code faster.
 
@paul23 Why not? I upgraded to the proper 3.6.0 in January, and also compiled it myself.
 
I have trouble compiling anything from source if its build procedure is anything more complicated than gcc main.cpp
 
1:17 PM
@Kevin Thankyou! I was trying to find that article a couple of days ago, to post in response to something DSM said (which I've since forgotten ;) ). But I couldn't remember the exact terminology, or where I read it... and ended up re-reading stuff in The Jargon File.
 
Ah, how fortunate.
 
\o cbg
 
FWIW, I also compiled the driver for my USB WiFi thingy. It came with Windows drivers and complete C source on a mini-CD for Linux users. I had to make a tiny adjustment to the makefile, so it probably would be a bit painful for a Linux user who isn't a C programmer, but hey what do you expect for $15?
 
1:33 PM
Rather you than me. I only remember the massive dependency problems when trying to compile any library.
 
cbg all
 
cbg
 
@PM2Ring Python is easy to bulid with the usual dance: ./configure && make && make install
 
C:\Users\Kevin\Desktop>make
'make' is not recognized as an internal or external command,
operable program or batch file.
Such is the hellish twilight existence of a Windows user.
 
@holdenweb I think I also did a make test. When I compiled the alpha version of Python 3.6 I had to do a few extra things because the distro I use (Mepis) is rather ancient (and now abandoned by its developers), and I needed to fiddle around with my repos to install a few bits & pieces I didn't have.
 
I hate when business change the requirement to the point where I have to change 80% of my code :\
 
DSM
Consider it an opportunity to think of ways to design the system so that the next time you'll only have to change 8%.
Thursday cabbage for all!
 
cbg!
 
@Kevin It's possible to install Open Source C compilers on Windows machines, but traditionally Microsoft haven't made it easy. So the usual workaround is that you have to install a POSIX-like environment inside Windows (like MinGW), and the compiler can live in that.
 
@DSM Can safely assume that even if your design is perfect, the business can still make demands that you will definitely have to make huge changes
 
1:50 PM
I've got mingw installed, I think. But I think I ticked the wrong boxes during installation, because now I only have access to gcc and grep and seemingly nothing else
 
@Kevin Oh. And gcc without make is fairly limited.
 
@DSM :\ I guess, I just need to think more module, allowing adding to my code rather than my current box coding :\ also morning :D
 
Had I more gumption, the correct course of action would be to try and reinstall. But I haven't got the gumption, as previously established.
(inb4 "no the correct course of action is to get a real OS")
The room regulars sigh and collectively add a mark to their "times Kevin has complained about a problem despite knowing exactly what is required to solve it" tallies
 
cabbage all
 
cbg
 
1:59 PM
cbg
 

« first day (2357 days earlier)      last day (2577 days later) »