« first day (2413 days earlier)      last day (2551 days later) » 

5:16 AM
The stat description says "viewed" x number of times. That doesn't mean it was viewed by x different viewers, but y viewers (<= x) viewed it x number of times.
A let down for me too, I thought I reached / helped 315k devs, but I might have instead helped 315k times for a likely less than 315k devs.
 
 
4 hours later…
9:13 AM
def find_epoch_delta1(sorted_netflow):
for dst_ip in np.unique(remote_host_list):
print "DST : " + dst_ip
for src_ip in np.unique(client_ip_list):
print "SRC : " + src_ip
a = np.array(sorted_netflow)
arr_index = np.where(a == dst_ip)
#print arr_index
filt = a[arr_index]
for num in range(0,len(filt)):
if num != (len(filt) - 1):
epoch_delta = int(filt[num]['timestamp']) - int(filt[num + 1]['timestamp'])
#print abs(epoch_delta)
final_info = {"client_ip": src_ip, "remote_host": dst_ip, "epoch_delta": abs(epoch_delta)}
I want to avoid for loop and execute it very fast
 
9:37 AM
@DhananjayaGupta The indentation is pretty screwed. Kindly correct it & use pastebin for the dump instead of pasting the code here. Please see room rules for the guidelines - sopython.com/chatroom
 
10:05 AM
cbg("*", morning=True, tz=pytz.timezone('Europe/London'))
 
10:45 AM
Someone with relevant reputation. Could they help me move my question stackoverflow.com/questions/44176433/… to dsp.stackexchange.com . I had checked this link and also raised a moderator flag. meta.stackexchange.com/questions/85017/…
Do I need to repost it
 
11:06 AM
cbg
@AkshayHazari regular users can only vote to migrate to a handful of sister sites, and signal processing is not one of them. You did right for flagging for a mod, now I suggest that you wait for your flag to be handled.
posts can be migrated for something like 60 days, so there's no rush
you can follow your flags here
 
user6845426
11:33 AM
cbg
 
cbg
 
user6845426
long time no speak
 
yup
 
user6845426
hows it going
 
Fine, thanks. How about you?
 
user6845426
11:39 AM
Meh not bad. I have an exam in the morning so currently stressing
 
break a leg:)
what is it about?
 
user6845426
Machine Learning module
 
cool
 
user6845426
Minus any equations, its more just general knowedge of unsupervised/supervised methods
 
I can see why that would be useful
even simple concepts such as gradient descent can be easier understood when not fully formalized
 
user6845426
11:43 AM
We're covering k-means, gmm, pca, lda, regression, svm's, nn's
 
user6845426
Finding it quite interesting though
 
I had a brief run-in with k-means during my early days on SO :)
 
user6845426
I've played around with k-means a bit in matlab
 
user6845426
I applied for a ML job and they use R. I've never looked into that language though
 
bleh
 
user6845426
11:52 AM
You looked at R?
 
briefly, then I had to look away ;)
I only looked long enough to develop an adamant unfounded prejudice against the language
 
user6845426
LOL
 
user6845426
great xD
 
12:34 PM
>>> import tkinter
>>> tkinter.filedialog
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tkinter' has no attribute 'filedialog'
>>>
>>> from tkinter import filedialog
>>> tkinter.filedialog
<module 'tkinter.filedialog' from 'C:\\Programming\\Python 3.5\\lib\\tkinter\\filedialog.py'>
I find this behavior curious.
After from tkinter import filedialog I expect the name filedialog to be bound to the filedialog module. I expect tkinter.filedialog to continue to raise an AttributeError.
The only time I'd expect tkinter.filedialog to not raise an AttributeError is if I did import tkinter.filedialog. But that doesn't appear to be how things work.
 
sqlalchemy ORM question - I've got an Enum, and I want a class that has a many-to-one relationship to that enum, what's a good way to model it. I'm currently thinking that I should wrap the enum into a table and then have a regular many-to-one relationship with it
 
> When a submodule is loaded using any mechanism (e.g. importlib APIs, the import or import-from statements, or built-in __import__()) a binding is placed in the parent module’s namespace to the submodule object. For example, if package spam has a submodule foo, after importing spam.foo, spam will have an attribute foo which is bound to the submodule.
 
>>> import tkinter
>>> dir1 = dir(tkinter)
>>> from tkinter import filedialog
>>> dir2 = dir(tkinter)
>>> [d for d in dir2 if d not in dir1]
['commondialog', 'dialog', 'filedialog']
 
Ok, so at least the behavior is well-documented
 
I guess tkinter.filedialog's __all__ contains these 3 items?
no, it doesn't
instead
from tkinter import *
from tkinter.dialog import Dialog
from tkinter import commondialog
 
12:46 PM
I expect that filedialog merely imports those. Oops beaten.
 
I also found a severe PEP8 violation
def askdirectory (**options):
 
So in general you can't predict what mutations will be made to a module's namespace by subsequent imports of other modules, since those modules can themselves import other modules.
Other than the prediction "a nonzero number of bindings will be added to some modules"
 
at least if you import tkinter.filedialog directly, you'll end up with the same dir(tkinter)
 
Yeah the docs say fairly explicitly that the module mutation happens regardless of how you're performing the import, so import x.y and from x import y do the same thing in that respect
 
I just find this all a bit weird
 
12:49 PM
> Given Python’s familiar name binding rules this might seem surprising, but it’s actually a fundamental feature of the import system.
 
but I know next to nothing about python's import mechanisms
I'm glad it's supposed to be weird if you're unfamiliar with the import system
 
^^^ At least they acknowledge that what is effectively assignment-with-side-effects is unusual compared to more mundane language elements
 
1:05 PM
Can you change the labels of a pull request on a github project you aren't a member of? I submitted a typo fix to cpython and it indicates that it should have a "trivial" label if there's no associated issue number.
I'd be happy to add it myself but there's nothing clickable in the "label" sidebar like there is when I own the project
 
I only know that any annotations to issues can only be added by project members...which would make me unsurprised if the same applied to PRs
 
Somebody else set the label for me. Problem solved.
Hmm I recommended changing "an __path__" to "a __path__" but this is arguable depending on whether you pronounce it as "path" or "underscore underscore path underscore underscore"
Maybe I should have made that a separate pull request from the other typo fix suggestions I made, which were more objective
Exercise: scrape the documentation for all instances of "a(n?) <backtick><backtick><underscore><underscore><non-vowel letter>" and see which variant is more frequent
 
1:22 PM
\o cbg
 
or "dunderscore path"
 
1:34 PM
grep reveals that there are appx 50 instances of "a __" in the docs, and five instances of "an __" in the docs, with "an __path__" being the one and only instance where the following letter is a consonant.
Ok, I've been sidetracked twice from my actual goal, which is to determine the precise behavior of a script that imports a module that imports the script.
I think the rules are:
- once a module is imported, additional imports of that module will not cause any of the code in that module to execute.
- the `__main__` module is considered distinct from the module created when you import the main module's filename, so in this case (and this case only) that file's code may execute twice
#main1.py
print("About to import A from main1.")
import a
print("A imported from main1.")

#a.py
print("About to import main1 from A.")
import main1
print("main1 imported from A.")

#output:
C:\Users\Kevin\Desktop\import_test>main1.py
About to import A from main1.
About to import main1 from A.
About to import A from main1.
A imported from main1.
main1 imported from A.
A imported from main1.
Breakdown of events:
1. The program begins to execute. Before any statements are evaluated, a module object for `__main__` is created.
2. __main__'s "About to import A from main1." is printed.
3. __main__'s `import a` executes. No module by that name exists yet, so a module object for `a` is created.
4. a's "About to import main1 from A." is printed.
5. `import main1` executes. No module by that name exists yet, so a module object for `main1` is created.
6. main1's "About to import A from main1." is printed.
7. main1's `import a` executes. A module by that name already exists, so nothing happens.
8. main1's "A imported from main1." is printed. main1 completes executing.
9. a's "main1 imported from A." is printed. a completes executing.
10. __main__'s "A imported from main1." is printed. __main__ completes executing. The process terminates.
 
1:54 PM
you can have my quatloos
 
Contrast this with a circular import where the module being imported is not the same file as __main__'s:
#main2.py
print("About to import B from main2.")
import b
print("B imported from main2.")

#b.py
print("About to import C from B.")
import c
print("C imported from B.")

#c.py
print("About to import B from C.")
import b
print("B imported from C.")
C:\Users\Kevin\Desktop\import_test>main2.py
About to import B from main2.
About to import C from B.
About to import B from C.
B imported from C.
C imported from B.
B imported from main2.
"About to import C from B." appears only once. If we had executed b.py directly from the command line, "About to import C from B." would appear twice.
The practical lesson learned here is "avoid importing the file that you're executing from the command line, even if this requires you to have a file containing nothing but import actualmainfile"
And/or "put if __name__ == "__main__": around all the code in your main file that has side effects"
 
2:25 PM
\o cbg Wayne and Dsm :D
 
On reflection I think the second lesson there is more practical than the first.
 
DSM
Thursday cabbage for all.
 
Hope you stay dry
 
Even though just having a name guard doesn't prevent your functions and classes from getting evaluated twice, that's almost never going to be a performance bottleneck because it will be reevaluated at most once, so it's still an O(1) penalty unless you're doing something incredibly weird
 
can I write something in a requirements file like package>2.0,<3.0 or something like that?
I know I can do >2.0
pip.pypa.io/en/stable/user_guide/#requirements-files suggests I can do pkg3>=1.0,<=2.0 but if I try to actually pip install with that it fails
or perhaps... that's not allowed syntax in a manual pip install pkg3>=1.0,<=2.0
ah. need quotes...
 
2:39 PM
I'm tempted to suggest trying 2.0<package<3.0 but I'm guessing requirement file syntax isn't identical to Python's comparison chaining syntax
A parser not written by a madman would probably expect the package name to come first
 
@Kevin this seems to work:
in the requirements.txt the pkg>=1.0,<2.0 syntax
but to do a pip install it needs ` around it...
pip install 'pkg3>=1.0,<=2.0'
 
I'll try to remember that for the next time I need a requirements document.
 
I should really do that with setuptools. they seem to break things on major releases... often
and the way pip works it happily installs the next major release without caring about that ;)
 
My cpython pull request got replied to by a bot named "Knights who say Ni". I appreciate the devotion to the brand, there.
 
@Kevin linky?
 
lol nice
 
I saw that bot the other day
right, when Kostya found that null-char bug in readline()
 
Git quesiton: If I have version 1 code, and version 2 code, and I add new code to version 2 which I want to bring into version 1, when I merge version 1 into my new branch (that includes new code), I get conflicts for the whole project (minus the newly added code), is there a way to take the source for everything since there's no conflict for the new code ?
basically I want to just copy and paste my new code into version 1.
right now I'm just in VS clicking 'take source' on every conflict...
 
I should learn how merging works one day.
 
zzz I ended up just checking out Version 1 and manually putting my new code in there and calling it a day
save me from clicking 'take source' on 300+ files
 
3:09 PM
Frustrating when the "right" way is so much more difficult than the "wrong" way despite having the same ultimate outcome
At least when the wrong way is brittle or hacky or whatever you feel like there's a proper karmic balance to things, but when there's absolutely no risk or punishment it feels like an injustice is occurring
 
3:38 PM
just found out that version 1 has a different style than version 2, and therefore i have to rewrite code and maintain two different versions that does the same thing :\ Oh well work is work I suppose
 
3:59 PM
@Kevin the first project I ever worked on with git I did 100% of merge conflicts manually by pulling down the repo, then copying my changes manually :|
 
4:14 PM
@MooingRawr I've been using git from command line nearly exclusively for about a year and a half and it has greatly improved my conceptual understanding of it
when you do things on command line you have to know what you are doing a lot more than with a GUI
 
4:34 PM
cbg guys
 
I think im getting a syntax error on this but im not sure why: lengths = len(x) for x in (w, a, d, s, wa, wd, sd, sa, nk)
 
lengths = [len(x) for x in (w, a, d, s, wa, wd, sd, sa, nk)]
Or lengths = (len(x) for x in (w, a, d, s, wa, wd, sd, sa, nk)) if you want it to be a generator but that's not as common
 
whats the difference?
in the result that is
i just want to quickly get the lengths to print them to check
 
List comprehensions evaluate to a list. Lists can be iterated over any number of times, and can be indexed. Generator expressions evaluate to a generator. Generators can be iterated over exactly once and can't be indexed.
 
I take it I need the list one
 
4:38 PM
Compare:
>>> x = [i**2 for i in range(3)]
>>> for item in x:
...     print(item)
...
0
1
4
>>> for item in x:
...     print(item)
...
0
1
4
>>> x[1]
1
>>> y = (j**2 for j in range(3))
>>> for item in y:
...     print(item)
...
0
1
4
>>> for item in y:
...     print(item)
...
>>> y[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'generator' object is not subscriptable
 
i have 2 strings, say string1 and string2. I want to check if more than 50% (in terms of # of words) of string1 is in string2. the technique i thought was to check for each word in string1, if it is in string2, calculate the number of words for which this is the case, and then divide that number by the length of string1. If this fraction is >0.5, I say yes. But is there an easier way?
 
Thanks @Kevin
 
@user1993 Do you care about duplicate words?
>>> s1 = 'this is a string containing some words'
>>> s2 = 'this is also a string'
>>> s3 = 'so is this'
>>> len(set(s2.split())) > len(set(s1.split())) / 2
True
>>> len(set(s3.split())) > len(set(s1.split())) / 2
False
^ if not, this works.
Aargh, forgot to split
 
no, i dont want to see if the number of words is >50%, but rather the WORDS themselves
 
I'm not sure exactly what you want then. Example?
 
4:49 PM
If I understand correctly: s1's words "this", "is", "a", and "string" are also in s2. So the s1-to-s2 score is 4/7. s1 and s3 only share two words in common, so the s1-to-s3 score is 2/7.
 
EXAMPLE
s1='this is a string with some words'
s2='this is a string hire me'
s3='this is a string hire me please hire me'

YES for s2 (4 out of 6 words are in s1), NO for s3 (only 4 out of 9)
 
The operation is argument-position-dependent: the s1-to-s2 score will be different from the s2-to-s1 score, if they contain a different number of words.
 
@Kevin, i just want the words to be there somewhere, no need for them to be in order
 
I'm not talking about the order of words in the sentence. I'm talking about the order of the sentences with repsect to each other.
 
DSM
[unixODBC][Microsoft][ODBC Driver 13 for SQL Server]SSPI Provider: Server not found in Kerberos database (851968) (SQLDriverConnect)' <- why does this stuff always happen on Thursdays?!
 
4:52 PM
In the example you just gave, s3-to-s1 is 4/9, but s1-to-s3 is 4/7.
The denominator changes depending on which sentence you're checking the word count of.
 
@Kevin ok, so the s1 is independent, call it s. we are only interested to check which of s2 and s3 follow this condition
@ZeroPiraeus, you can have a look at the example
 
Also forgot to actually do the set intersection … I think I should give up and become a carpenter.
 
DSM
Honourable work. I approve of the trades.
 
slices off own thumb with chisel
 
DSM
The size of the intersection over the size of the union would be an order-independent measure of similarity.
 
4:56 PM
It's not necessarily bad to have a non-commutative operator, but you do need to consider whether it truly makes sense in your business logic
 
@DSM are you talking to me?
 
DSM
@user1993: conversations around here aren't quite so linear. :-) It was just a thought I had based on Kevin's observation.
 
ok. so again, s1 is independent, and every string (like s2, s3..) is being compared to it
 
What I'm hearing is "I don't mind if it's non-commutative". That's fine. You do you.
 
DSM
Decide on whether or not you care about cardinality (how many times a word appears), which will tell you whether you should use a set or something like a Counter. Then, well, use one.
 
5:02 PM
ok. so in my case, all the strings (s2,s3...) have no repeating words
 
def similarity(s1, s2):
    wc1 = Counter(s1.split())
    wc2 = Counter(s2.split())
    common = wc1 & wc2
    return sum(common.values()) / sum(wc1.values())
>>> pprint(ss)
{'s1': 'this is a string with some words',
 's2': 'this is a string hire me',
 's3': 'this is a string hire me please hire me'}
>>> for a in ss:
...     for b in ss:
...         print(a, b, similarity(ss[a], ss[b]))
...
s2 s2 1.0
s2 s3 1.0
s2 s1 0.6666666666666666
s3 s2 0.6666666666666666
s3 s3 1.0
s3 s1 0.4444444444444444
s1 s2 0.5714285714285714
s1 s3 0.5714285714285714
s1 s1 1.0
Caveat: possible typos; thumb missing.
 
@ZeroPiraeus, it says NameError: name 'Counter' is not defined. is it just len() ?
 
from collections import Counter
 
thanks, but is it the same as len()? i tried to google the difference but couldnt find anything
 
It's not the same as len.
 
5:12 PM
oh
 
ValueError: Cannot feed value of shape (64, 4) for Tensor 'targets/Y:0', which has shape '(?, 3)'
Any idea what I need to be looking for?
 
They're as different as a fish and a bicycle so it's hard to give a bulleted list of differences
@mtbrands Sounds like you've got an array somewhere that's the wrong dimensions.
 
Hi, I am new to Python. Facing the following error:

TypeError: 'Pagination' object is not iterable

Can anyone help me out?
 
I guess, Ive been looking through my code but cant find where it states what it expects
 
5:14 PM
@chiragshah Sounds like you've got a for loop that's iterating over something that can't be iterated over
 
@kev
 
Or you're calling list on an object that can't be iterated over
 
@Kevin Im trying to iterate paginated object
 
@Kevin ok :). But i was wondering what extra help it gives in this particular case
 
I don't know what a paginated object is, but I bet you can't iterate over it
 
5:16 PM
@Kevin

if(word is None):
records = Word.query.order_by(desc(Word.created_at)).paginate(page, 8, False)
else:
records = Word.query.filter(Word.word.like('%' + word + '%')).paginate(page, 8, False)


I'm trying to iterate records object
 
@chiragshah You don't need to '@' people every time.
@chiragshah it's superfluous.
 
@user1993 It's helpful because you can call .values() on a Counter, but you can't call .values() on the int returned by len
 
@chiragshah and after a while it gets quite annoying.
 
got it
 
@Kevin ?
 
5:20 PM
Yes?
 
if(word is None):
records = Word.query.order_by(desc(Word.created_at)).paginate(page, 8, False)
else:
records = Word.query.filter(Word.word.like('%' + word + '%')).paginate(page, 8, False)


I'm trying to iterate records object. Can you help me why am I not able to iterate
 
I don't know anything about whatever library you're using, so I've given all of the advice I'm able to give.
 
@Kevin Using flask framework
 
I see. I don't know anything about Flask.
 
And why don't you think you're able to iterate? By the way, that's Flask-SQLAlchemy, not Flask.
 
5:26 PM
I don't know.
for element in records:
print ('Something')

Trying to iterate it this way. And it throws me an error :
TypeError: 'Pagination' object is not iterable

I don't know what I'm doing wrong. Beginner to this
 
perhaps the problem is related to pagination objects not being iterable
recbg
 
Assuming that we really can't iterate over pagination objects, perhaps the question to ask is "what should I be iterating over instead of the pagination object in order to get the behavior I want?". Although we can't answer that until we know what behavior you want.
 
DSM
I have made fire! I can now avoid having to drop out into Windows to work on this one codebase.
 
Pardon me if I'm off-base here since I haven't got any relevant domain knowledge here
 
@Kevin May be this is what I am trying to achieve
 
5:31 PM
@chiragshah iterate over the Pagination object's items attribute.
 
@davidism Thanks
 
What did we ever do to deserve davidism
 
So I just released a new version of WereSync (https://github.com/DonyorM/weresync). I'd love any feedback you all have to give.

WereSync incrementally clones linux drives, but can do so to a smaller drive and from a running one, unlike anyone existing cloning software (as far as I know). This update gives better support for making the clones bootable, making them more useful. It's written in Python completely (but calls a lot of subprocesses)
 
@Kevin The Web Developer We Deserve.
 
Too much pressure, I'm going to delete everything and disappear now.
 
5:45 PM
Here, I'll dial back.
 
the day when exploded
 
 
:-|
 
C??? D:
@poke you were right, mod found no evidence of voting irregularities on that crappy-but-upvoted post
 
"Your presence is preferable to your absence. Take this." [hands you a sealed ziplock bag of confetti]
 
6:39 PM
A recent question says, "this code might make money if used to trade stocks in stock market." Love that optimism.
 
Does the code have a NOEL constant?
 
Hmm, not sure if reference to an economics term I'm not familiar with, or an implication that an actually profitable stock automation program is so rare and valuable that you can only get one at Christmas if a supernatural entity decides you're worthy.
 
6:54 PM
I suppose that's about as effective as any other stock picking algorithm, on average
 
Ah, here we go (actual source): books.google.cl/…
 
> You have reached your viewing limit for this book (why?).
Europe says thanks :P
 
I also can't read it. America is supposed to have all the nice things B-(
 
I guess Google Books is region locked. My search term in Google itself was "This was Noel Constant's system", which produced a small number of hits, the last of which was the novel itself, Sirens of Titan.
 
I'm trying to install pip on a MacOS without root/administrator rights, so following this post askubuntu.com/questions/363300";, with command "python get-pip.py --user" errors with "DistutilsOptionError: can't combine user with prefix, exec_prefix/home, or install_(plat)base", but "python get-pip.py" without "--user" says "Successfully installed pip-9.0.1 wheel-0.29.0", then "pip" command returns "-bash: pip: command not found" how can i get pip installed as user?
 
7:08 PM
(Is there no easy_install for mac? That's what that Q&A seems to be talking about)
disclaimer: I don't know macs, and my debian comes pre-bundled with pip
 
Maybe its pip3?
 
I dunno, I've always steered away from easy_install preferring pip
can't get pip3 either, only have access to Mac system installation python2.7 /usr/bin/python
 
as in the command pip3 instead of pip. I installed python on an ubuntu server last night and ran into a similar problem until I realized it had made all paths related to python 3 not just "python" but "python3" "pip3" etc.
Oh for 2. Maybe try pip2? lol
 
well it did say "Successfully installed pip-9.0.1 wheel-0.29.0" but where did it install to?
 
Did you echo $PATH ?
Does it show up anywhere there?
 
7:14 PM
I have tried to modify the $PATH, inside "~/.local/bin/" shows a "pip" directory, and other directories "pip-9.0.1.dist-info, wheel-0.29.0-py2.7.egg-info, pip-9.0.1-py2.7.egg-info, wheel, wheel-0.29.0.dist-info"
not sure if a pip executable is in there, but I have that directory in my $PATH
oh well, thanks for the ideas :)
 
Which one do you prefer?

print(sum(value // 2 for value in Counter(c).values()))

print(sum(map(lambda x: x//2, Counter(c).values())))
 
First one. I reserve map almost exclusively for situations where I don't need to give it a lambda.
 
ahh okay.
 
Ex. "".join(map(str, range(10)))
 
I find it hard to choose between the different ways of writing the solution.
 
7:29 PM
If you've got working and understandable code, don't sweat it too much. "Pythonic" is largely a collective daydream.
 
DSM
But a beautiful one.
 
sometimes more like a fever dream
 
Write one that you could accept showing it to other people. Mainly don't let future-you down!
 
More like a wet dream :)
 
@MooingRawr the only person worse than future-you is past-you
 
7:41 PM
cbg
 
Whoops I tried to fast gun a question and my first three revisions were horribly formatted messes so I got no points
Quick substantial editing is only a good strategy if you get down something that's actually factually correct the first go-round
 
8:38 PM
I hate it when I finish all my things to do before 5 :\ so boredom
 
 
2 hours later…
10:13 PM
Hi - I am new to Python can anyone throw some lights on stackoverflow.com/questions/43354388/…
 
@Rajeev You should really take a look at our room rules
 
DSM
@WayneWerner: seems a reasonable enough question; it's been more than a month, and the only answer doesn't seem to work for him.
 

« first day (2413 days earlier)      last day (2551 days later) »