« first day (3295 days earlier)      last day (1873 days later) » 
02:00 - 20:0020:00 - 23:00

02:42
@AnttiHaapala That link was interesting, a bit over my head as I don't fully comprehend all the C and under the hood python stuff. I don't remember the conversation/context of why you were pinging me though?
03:00
cbg
I sort of wanna challenge stack overflow to see how they fair against our cousins in the mathematica stack exchange with this, but how could I turn it into a good question...

https://mathematica.stackexchange.com/questions/120041/how-to-generate-image-like-qr-code-with-mathematica
 
5 hours later…
07:42
cbg, all, bugrit.
@ReblochonMasque No, you were just replicating the python-dev debate before PEP 8 was updated.
07:58
@roganjosh this seems like an interesting question if the OP would not have axed it :/
it appears they basically want a contextvar
08:42
@Skyler you can't. That's more like a task for codegolf.SE
09:31
cbg
 
2 hours later…
11:42
@roganjosh I saw a tweet that showed examples of the problem that was solved, but the link was to asahi.com.jp, so all Japanese (which I may read some day, but that is not yet this day). Does anyone have a link to an English-language page that describes just what the quantum computer's mathematics did?
11:52
Found this on python website: In general, the iterator forms are more memory friendly and more scalable. They are preferred whenever a real list is not required.. The question: if I am already supplied a list in a function and I have no choice but to use it, does it make sense to make an iterator out of it first?
Only if you need an actual iterator (because you want to call next() on it, for example)
What is the benefit of that over using collections.deque?
wha? Why are we suddenly comparing apples to oranges?
deque is for when you need to pop/insert efficiently from both ends. iterators are for iterating.
once you are done iterating, isn't the iterator null? So wouldn't that be equivalent to just popping from a deque?
...I guess you could say that. A deque is less efficient than an iterator though
12:00
from the space complexity / memory standpoint?
and speed as well
Calling iter on a list and iterating over the result is less memory friendly than just iterating over the list. An iterator is memory friendly if the items it is yielding aren't already fully loaded in memory somewhere. Examples: a file object; virtually everything returned by an itertools method
12:13
@Kevin awesome!
Just did a test. wrote one python file that does: for i in range(1000000): 10**2 and another one for i in range(1000000): pow(10, 2) and the former takes 4 times longer (did time ./speed.py).
That's surprising to me. for i in range(1000000): 10**2 shouldn't even be doing any arithmetic, since the parser can turn 10**2 into 100 while it's compiling the bytecode
@isquared-KeepitReal Runs counter to every test like this I've ever seen.
import timeit
timeit.timeit("10**2")
0.014188182991347276
timeit.timeit("pow(10,2)")
0.3431729570002062
pow is about 30X slower
If we pre-resolve pow, its a bit better
timeit.timeit("pow(10,2)", setup="import math; pow=math.pow")
0.1356628549983725
Only about 10X slower
If you compare their byte codes, they run identical code except the pow approach has five extra instructions (12 through 20)
@isquared-KeepitReal time is useless for profiling code
@AndrasDeak that code was just a line of code. quick hack
12:20
@Kevin Not all byte codes are equal in time - CALL_FUNCTION is a killer
@isquared-KeepitReal quick non-working hack
If you want to do timing like this, learn the timeit module.
It's akin to measuring the volume of a beaker by measuring the increase in water level in a water park's wave pool
@isquared-KeepitReal Well it gave you misleading results, so that might be considered "non-working"
12:21
@PaulMcG I am aware of it, I just don't know how to do out from outside the python code. But now that I think about it, I don't need to. Could have done it inside. Noted
@PaulMcG Yes, I agree. So you can't say "X has fewer instructions than Y, therefore X is faster". But you can say "X runs exactly the same instructions as Y, except Y has a couple more, therefore X is faster"
@isquared-KeepitReal you can't do it from outside
If you measure the interpreter you've already lost
@AndrasDeak noted, thanks
You can import it as a function though, so that's semi-outside
@PaulMcG how did you identify that this byte code is the performance drag?
12:23
Timeit has a command-line form, doesn't it? I can never remember the syntax for that.
python3 -m timeit 'for i in range(1000000): 10**2' should work
In this specific instance, the CALL_FUNCTION byte code at address 4 does not cause one approach's performance to drag compared to the other, because both approaches call the same function with identical arguments. But in general, a CALL_FUNCTION instruction can take literally any amount of time. For all we know, the function being called is time.sleep(10**100)
@Kevin The CALL_FUNCTION at address 4 is calling range. Within the iterator, only pow does CALL_FUNCTION. 10**2 just loads the computed-at-compile-time constant.
So 10**2 is literally faster
Even functions that just return a constant incur a penalty vs. just using the constant.
12:29
Or maybe I misunderstood and you're saying "how do you know that the CALL_FUNCTION at address 18 is the bottleneck for the second approach, compared to the other four instructions that are exclusive to the second approach?". That's not something that's easy to prove conclusively, but it's a reasonable guess. "Function calls are slow" is common wisdom
@AndrasDeak I see what you did there
numba.jit would devastate that loop
I now replace all calls to random.random() with 4
Much faster
@PaulMcG Yeah. To add insult to injury, the 10**2 approach doesn't even load the constant, because it's never used.
Hah, yes! It just loads the None return value
12:31
It shows up if you do something like dis.dis("for i in range(1000000): x = 10**2"), and as you say, the 100 constant is calculated at compile time
So really just doing timing on iterating over the range
@isquared-KeepitReal forcing input to some equivalent form has no advantage, but choosing a different output type does. for example, filter doesn't care if it is given a list/iterator/generator/sequence/... but always gives an iterator.
A digression I wanted to insert a while back: Even though iter(my_list) doesn't confer any speed advantages, it can still be useful for other reasons. If you ever find yourself thinking "I wish I could do i += 1 inside my loop and make it understand that I want to skip the next iteration", then you could do something very much like that by calling next on the iterator.
Extremely contrived example:
def frotz(the_list):
    """get every element of the list, except elements appearing immediately after an odd number"""
    g = iter(the_list)
    for x in g:
        yield x
        if x %2 == 1:
            next(g)

seq = [4, 8, 15, 16, 23, 42]
print(list(frotz(seq)))
#[4, 8, 15, 23]
Please ignore corner cases such as "what if the list ends with an odd number?" and "what if two odd numbers are next to one another?"
12:41
that's actually pretty well-defined by your docstring.
You're on your own if you want to do the equivalent of i -= 1, though. There's no prev(g) function, alas.
API preference: would you prefer having two top-level methods to get generic and specialised result, or one top-level for the generic and a chained method for the specialised result?
# B
await foo.volume(5000)
async for bar in foo.chunks(5000, 10): ...

# B
await foo.volume(5000)
async for bar in foo.volume(5000).chunks(10): ...
Mild preference for the second one
cbg
Mostly because I can make some deductions about the type of the return value of foo.volume, namely that it can't be any built-in type, since none of those have a chunks method. But presumably the actual users of your API already know that, so that's not much of a benefit
12:53
cbg
@Kevin every method returns mildly scary async/await magic pixie helpers representations
Comedy option: implement both approaches at the same time
I was considering that, but got confused myself while drafting already :/
What happens if someone does v = foo.volume(5000); async_next(v.chunks(10)); async for bar in v:?
In terms of style the first is a bit shorter to type, but you get more of an OOP approach with the second (and it seems better for error checking because you could do vol.chunks(10) so I would probably go with that.
@Aran-Fey v itself would not be an AsyncIterable. However, every Awaitable in the rest of the API so far is a stateless request anyway, so await v; await v would be fine as well and correspond to await foo.volume(5000); await foo.volume(5000)
13:05
Hmm, ok. It's hard to say, but I think I've got a slight preference for the two top-level methods.
I think it probably depends on how these would be used. Would it ever make sense to assign v = foo.volume(5000) and then do both await v and async for bar in v.chunks(10)? If it doesn't, then foo.volume(5000).chunks(10) is basically just a silly syntax for what should be a foo.chunks(5000, 10) function call
hm, that's actually a good point. I don't think defining a volume and then fetching it via iteration would yield expected behaviour for most people. mainly because it would be two separate volumes.
dir_path = os.path.join(os.path.dirname(__file__), 'audio')
for file_name in os.listdir(dir_path):
file_name = os.path.abspath(file_name)
mp3_to_wav(file_name)
def mp3_to_wav(audio_file_name):
if audio_file_name.split('.')[1] == 'mp3':
sound = AudioSegment.from_mp3(audio_file_name)
@MisterMiyagi I define chunks as a wrapper on islice, so that I can pass it any sequence, generator, etc.: for bar in chunks(10)(foo.volume(5000)):
FileNotFoundError: [Errno 2] No such file or directory:
What could be the reason for the same.
@ravi - please edit your post (you have about 1-1/2 minutes) and use ^K to format as code
13:13
people can't adopt pathlib soon enough, I'm so tired of this listdir problem
@PaulMcG that looks pretty nifty, actually (even though it wouldn't work in my specific case). islicing iterables always strikes me as horrendously tedious compared to regular slicing.
@ravi os.path.abspath(file_name) will add the current working directory to the filename, not the directory that file_name is actually in. Try file_name = os.path.join(dir_path, file_name) instead.
@PaulMcG Have you considered some islice/[] mashup so that e.g. s(my_iter)[1::3] would be possible?
@Kevin FileNotFoundError: [WinError 2] The system cannot find the file specified
Hmm. Maybe I'm misreading your code, then. Please post it again, with proper indentation. Consult sopython.com/wiki/… if you're not sure how to do that.
13:20
if __name__ == "__main__":
    dir_path = os.path.join(os.path.dirname(__file__), 'audio')
    for file_name in os.listdir(dir_path):
        #file_path = os.path.join(os.path.dirname(__file__), 'audio', file_name)
        file_path = os.path.join(dir_path, file_name)
        mp3_to_wav(file_path)
def mp3_to_wav(audio_file_name):
    if audio_file_name.split('.')[1] == 'mp3':
        sound = AudioSegment.from_mp3(audio_file_name)
Thanks, I'll play around with it and see what I can see.
@MisterMiyagi Not sure what s and my_iter are here. But something like chunks(some_sequence)[::chunk_size] looks kind of cool
@ravi Where does the error happen? What line?
@Aran-Fey sound = AudioSegment.from_mp3(audio_file_name)
I bet 5 quatloos that AudioSegment.from_mp3 is implemented incorrectly
13:25
@Aran-Fey that's much problematic yes. But do I have any other option for converting mp3 to wav.
The code works OK on my machine: pastebin.com/wZQtf8NF
So yeah, I'm real suspicious of that AudioSegment method. One way to really verify that you're calling it with the right argument is to do print(audio_file_name) right before calling .from_mp3, and then you can check each path printed in the file explorer to verify that it exists
Incidentally none of this is going to work if your package is compressed into a zip or a tar or something. I don't think that's the actual problem, but I ran into that exact issue last week so I want to warn against it
Assuming AudioSegment is pydub.AudioSegment, I'm inclined to believe that it's actually implemented properly
I'm also assuming there's no "Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work" warning being printed
Anyway, we know the listdir call worked, and from that we can conclude that file_name is valid. If python claims that it isn't, then we have no way of figuring out why without having a reproducible example on hand
omg python has string interning?
urgh
I hope I'm missing something
    print(event)
    print(event['event'])
    print(bytes(event['event'], 'utf-8'))
    print(bytes('hello', 'utf-8'))
    print(event['event'] is not 'hello')
output:
{'event': 'hello', 'data': {'id': 'towc', 'auth': ''}}
hello
b'hello'
b'hello'
True
the only reason the last bit is true is interning, right?
13:41
yes
thanks
@ravi did you change anything between getting this error and the one before? it seems strange that you would get the same error with different message.
Obligatory warning: 99.999% of the time, you should not be doing a is b when a and b are strings
is there a best practice for comparing those strings in these situations?
a == b
13:42
@Kevin 99.99% of the time, you should not be doing a is b
I see, thanks
@MisterMiyagi Also true.
does anyone here know matplotlib? I was trying to color my points on a scatter plot (output from kmeans) but they are coming out as levels of grey from white to black instead of actual colors
check whether your backend supports colors
various output formats are greyscale only
what do you mean by backend?
when I switch to c='blue' the points come out blue so the output does support color
13:49
@MisterMiyagi no
@erotavlas how are you setting the colour for your points, then?
plt.scatter(data[:, 0], data[:, -1], c=kmeans2.labels_, edgecolors='blue')
plt.scatter(centers2[:, 0], centers2[:, 1], c='red', marker='x')
plt.show()
mornin' folks!
just pass c the array of labels, it automatically sets a color for each, in the examples online its supposed to color them, but mine end up shades of grey
your labels wouldn't happen to be greyscale color codes, would they?
say, numbers?
13:58
I love how my question is marked as duplicate (which is legitimate) but the dupe doesn't have the solution being asked about x3
@MisterMiyagi well they are number (int) from 0 to 3, is that why?
good to know that I am not alone though haha
@erotavlas integers should be fine
e.g. pyplot.scatter([1, 2], [1, 2], c=[1, 3])
@BanjoFox I don't suppose await ctx.send("@{} your quote is: {}".format(member, response)) works?
cabbage guys
Train of ignorant questions coming your way.. I was thinking of contributing to github
14:08
@erotavlas did you set a colormap perhaps?
forked and cloned repo created a PR but the owner is not very active
now, if I have another PR to make do the PRs queue up or something?
how does it work?
should I wait till my first PR is accepted or rejected bfore submitting another one?
@BanjoFox it would help if your question were to say early on that you want to @ mention the user, not just mention their name. Either way, agree that the dupe is not helpful.
If the PRs don't overlap I think it's fine to submit both at the same time
If they both modify the same file then it might make sense to hold off on one, in the interest of preventing merge conflicts
@Kevin That was going to be my next question.. What if I want to make changes to that one particular file two times
repos and users can have an arbitrary number of PRs open at the same time.
14:11
@Kevin Ahh got it..
So , We have to wait till the owner takes time to address the PR ?
you should primarily consider whether contributing is worth your time if the owner does not respond.
months or years? I last saw him in like April of this year
how long have you been waiting?
unless it is some high-profile software, I'd consider 6 months enough to declare it dead.
@MisterMiyagi That makes sense.. Its not a fancy project but , its kinda on my level , something that I can actually be useful at :-P
If the PRs do overlap, it still might make sense to submit them at the same time, if you think the changes can be merged easily. If the PRs are modifying different parts of the file, dozens of lines apart, maybe that's fine.
14:13
@Kevin Right!..
@MisterMiyagi hmmmm
can you guys suggest some repos which would be good for starting with open source? PS: I am average coder.
Sometimes I feel like a programming machine , other times I wonder how did I even get this job.. Its a paradox.
"a project that has lots of low-hanging fruit and a dev team that's welcoming to new contributors" is an ever moving target because low-hanging fruit gets plucked very quickly
Suddenly the only issues left to solve are the hard and/or boring ones
@Kevin :-(
I am up for even documentation and the boring stuff
@MisterMiyagi -- Yeah... >.< I did say "mention" in the OP, but I clarified (AT)Mention in the update which was before the Dupe tag.
@MisterMiyagi -- This thread (second one listed in the dupe comment) seems to lead in the right direction, but (my opinion) the API docs are not particularly helpful for newbies
https://stackoverflow.com/questions/50262096/for-discord-py-how-would-i-turn-the-authors-id-into-the-discord-users-actual
I agree. that is what I want to do, but I am not smart enough to figure out how to implement that :)
```
member = guild.get_member(userID)
member.name # MyName
usrmention = member.mention
```
???
but that also presumes that I get the Guild info as well.
14:24
@Anarach I manage the pyparsing project, and am in the market for a bunch of new unit tests. Coverage is in mid 80%, and I have a list of tests that should move to at least 90.
@PaulMcG Sooo.. You are looking for like the QA ?
@BanjoFox await ctx.send(ctx.message.author.mention)?
@Aran-Fey -- I think I tried that and it complained that author did not have attribute 'mention'
Will give it another go this evening just to be 1000% sure :)
> author
>
> A `Member` that sent the message. If channel is a private channel or the user has the left the guild, then it is a `User` instead.
if you're testing in a private channel, mentions won't work scratch that, User has a mention attribute as well
Good to know :) I created a new Server just for testing so I don't use private channels
I also think the APIdocs should have stuck with "Server" because when I log into Discord I only see "Add Server" not "Add Guild" but maybe I am doing something wrong there as well?
15:16
Yesterday I had a headache and I took an aspirin and my headache eventually went away, and I thought "but you can't prove that the asprin improved things. For all you know, you have an adverse reaction to asprin that makes headaches last longer, and your headache would have dissipated twice as quickly if you had done nothing" and I think this is a sign that I should dial back my skepticism a tad
Disbelieving absolutely everything is an effective way of rooting out invisible problems in ambiguously worded SO questions but perhaps it's not the best thing to do when I'm just trying to exist in real life
:D
I've learned how to be less ambiguous on SO, but I am always proven wrong ;)
15:49
I need someone who makes design decisions for me so I can just write code without second-guessing everything all the time :I
hrrrm
I make design decisions all the time, but can't write code LOL
Sanity check: if A x B = C, and |A| = |B|, can I solve for B, given A and C? I'm thinking "yes" but my first attempt or two got bogged down with sqrts
I also think "yes"
If it helps, I can guarantee that C != (0,0,0)
oh, so x is cross product
15:56
??
wow... x is not same as * :D
ignore me
16:10
@PaulMcG Sorry, was away all day. There was a link to the Nature article listed by the BBC, with a supplementary of data. Is that what you're after?
@Kevin yes
I think. B is in the plane perp. C, as large as A. There can be a few solutions but |C|=|A|^2 sin(phi)
And right-hand rule chooses one of two solutions
@roganjosh IBM had some objections by the way
@roganjosh I don't think so. Maybe I misread/misconstrued the tweet
Has it been officially contested? I can see a blog
morning cabbage
16:26
I agree it's solvable, but I'm too stupid to do it. According to wikipedia, it's 3 formulas with 3 unknown variables - therefore, solvable.
@Kevin what mathematical entities are A, B, and C?
3d vectors
whoever specified font sizes in pixels on SO needs to be fired, ugh
16:43
@Aran-Fey actually, that's only true for 3 linear equations
with nonlinear equations there are no guarantees
Yeah, true. They are linear equations though, right?
@Kevin if you want an algo: phi = arcsin(|C|/|A|^2), then rotate A around C with angle phi, in the positive direction
@Aran-Fey |A| = |B| is not
@Kevin oops, I was wrong: there are always two valid solutions
The equation for cross product at the end of the coordinate notation section looks linear to me, but I suspect solving those will result in there being an infinite number of solutions
for a given phi you'll always also have 180-phi, so unless the angle is 90 degrees then you'll have two solutions
There are definitely infinity solutions if you don't restrict the magnitude of B, as indicated by math.stackexchange.com/questions/32600/…
16:48
@Aran-Fey oh yeah, A x B == C are 3 linear equations with 3 unknowns, but they are probably not independent equations
Hmm, I thought there would only be two solutions if A x B == A x -B for all possible As and Bs.
hmm?
A x B == A x -B is only true if the cross product is 0
I can implement my algorithm if that helps
it's anticommutative, so A x B == -B x A (but not A x -B)
yes
linearity (homogeneity) alone implies what I said
Perhaps an example would help. If A x B == C, and |A| = |B|, given A = (1,0,0) and C = (0,0,1), how many solutions for B are there?
16:54
Only one because |A| == |C| == 1, so sin(phi) = 1, so phi=90 degrees, so phi and 180-phi are degenerate. And the vector you need is "A rotated around C by +90 degrees", so B=(0,1,0)
but that's an edge case due to the fact that |C|/|A|^2 == +1
Ok, that makes sense.
<elevator music plays while I play with other examples>
that's about the only one I can solve on paper ;)
>>> invert_cross((1,0,0), (0,0,1))
[array([ 6.123234e-17, -1.000000e+00,  0.000000e+00]), array([ 6.123234e-17, -1.000000e+00,  0.000000e+00])]
guess I was wrong about the sign
(I mean, my above code was buggy, (0,1,0) is the correct solution)
17:12
Alright, I found an example that agrees with your assessment. In general, I see that (1,0,0) x (b.x, b.y, 0) == (1,0,0) x (-b.x, b.y, 0)
For any arbitrary b.x and b.y values
when b.x == -b.x, that's the degenerate "phi = 90 degrees" case you mentioned
indeed
@Kevin and that (+-b.x, b.y) corresponds to phi and 180-phi with the same sine
Clearly I just need to find some operation such that A @ B = |A| |B| cos(theta) N, and I'll be able to uniquely solve for B
N?
Oh, so you don't really need the cross product? What are you really trying to do?
N there is the same N described in wikipedia's cross product article: "n is a unit vector perpendicular to the plane containing a and b in the direction given by the right-hand rule"
17:27
Going up the XY problem ladder by one rung, I'm playing around with different ways to represent the idea of "vector A rotated about vector C by theta degrees". Dot product and cross product both give ways to relate vectors and angles, although both have degenerate cases, as we've demonstrated here
There are plenty of resources that will give me exactly the formulas required to perform this rotation operation, but I want to play around in the conceptual space in hopes of getting a better intuition
How are dot products degenerate?
I guess the better question is "how does the dot product come into play?"
Generally, for 2d vectors, A dot B == A dot (B reflected over A)
yeah, and for 3d you have a cone
I just wasn't sure how it came together with rotating around C
Or, is it the other way around... A dot B == (A reflected over B) dot B. Something like that.
17:31
@Kevin both, actually
:o
Ah, since a dot b equals b dot a.
the two cases are basically |A|*(|B| cos(theta)) and |B|*(|A| cos(theta))
Yeah.
I'm catching up on the conversation after doing some of my own work.
Selenium testing is miserable
especially because I'm just copy/pasting so much and not really refactoring pieces for reusability
18:02
can i make a hash table or really efficient dictionary as a django model
currently it is for a test case, but the reason it particularly is interesting because i may have a trillion rows down the line
(with a tuple as the key)
That's a lotta rows
The first part would be adding an index to one of the keys on your table?
but is it just as simple as making a model in django thats a dictionary
A dict will work for prototyping and mudpie-making, but unlikely to fit in memory with terarows of data
Also, yeah, a trillion rows is gigantic. I suspect this needs more specialist help from SQL
Or, you're hoping to keep that whole dataset in memory? I'm making the assumption here that the model is backed by a database
18:06
yea, not in memory
@Skyler what are you trying to do with that data?
Some time-series databases are designed to run in multi-TB RAM systems - mostly for financial apps where cost is easier to justify
the data is literally just read after a first time assignment, which is why a dict like structure is ideal
with many entries read infrequently and some read very frequently
I think MM's question is more about why you need to store so much data. What practical purpose does it serve?
In any case, I suspect that for something performant, you're in the realms of Hadoop/Spark or some other distributed system that has dedicated engineers to run it
say youre checking the state of a website and all its subpages, like you have a spider that spits out 0s and 1s for each corresponding page being broken or not (sorry i cant quite talk about the exact operation but this is similar). A hash table seems to makes most sense for quick access, so for testing making a model in django is good
but then you want to bind the model reference to a hadoop instance or something similar for when you need to scale
18:17
You're talking about Google-level stuff here, not some simple Django app
If you're scanning one trillion web pages, I think the speed of your table will be the least of your concerns
im also trying to understand how a django heavy project like disqus and instagram, which handle ~10-100 billion entries, would go about doing the organizing
entries monthly*
Something along these lines. But probably heavily tailored at each step. There is a longer ppt for Facebook but it's still not going to clarify too much
Facebook but from 2014 so probably already dated
@wim I've been working my way through this answer since we had our Flask discussion. I don't know if you've seen it before. Taking a fresh look, it doesn't seem completely nuts but ... convoluted, so I see your points.
wim
wim
18:41
I had not seen it before, cheers.
@Skyler you should be looking at proper data management techniques, e.g. sharding, DHTs and friends (I can recommend the CEPH thesis), as well as multi-level data storage, e.g. C++ STXXL, bcache, the like. Loading everything into one dynamically typed data structure on a single machine is not how one does these things.
otherwise, a heavy in-memory DB (software + hardware) such as SAP HANA would seem appropriate. Google also has several papers on how their infrastructure works.
A recentish question asks "why doesn't str.count find overlapping occurrences?" and it's been answered with "because that's what the documentation says it does" and that's true enough but I was hoping somebody would dig up a justification for it being designed this way
A little source diving leads me to the conclusion "Because Objects/stringlib/find is implemented using Objects/stringlib/fastsearch, and if fastsearch searched for overlapping strings, it wouldn't be fast". Ok, sure. But if speed were always prioritized over correctness, let's just do return 0 and be done with it
IIRC it's based on how str search algorithms work (in Python).
So the justification can't just be "because it's faster this way"
@Kevin return 0 is never correct. str.count is correct whenever no overlapping occurrences are desired.
18:47
Perhaps the missing piece is "because in the vast majority of cases, the target string can't overlap with itself, so we're making the common case fast at the expense of making the uncommon case give a surprising result"
"never" meaning "except a finite number of cases", of course
:-P
Almost all integers are nonzero, after all
I blame it on my Math education. really harmful to minors.
it's always good style to drop constant terms.
The only true constants are death and taxes and I'm happy to drop them both
I'd be willing to add "python packaging" to the list.
wim
wim
18:58
constantly broken? :)
it's definitely close to death and taxes.
though I'm rather happy with flit lately.
it's just a pain to migrate all the old stuff...
0
Q: how to return the quadrant inside which a is a given point, without using if statement?

pooya shamsIm doing a c++ homework that asks me to write a program that gets two inputs x and y of a point, and returns the quadrant which the point is inside. we are not supposed to use any if statement and we can just use these operators = + - * / % () and abs function of math.h header file we can't use a...

Is this even possible with the restriction of not using an if statement?
@Kevin How'd the vector math go?
@MisterMiyagi how?
It has been proved to my satisfaction that dot products are not reversible even if you know the magnitude
19:10
cross products
Yes, cross products. Dot products too, but mainly cross products.
@Code-Apprentice the most simple approach is to exploit that booleans are integers
How do we do spoilers again?
(x > 0) * (y > 0) * 1 gives 1 for the positive quadrant, 0 otherwise
@Code-Apprentice does a ternary operator count as an if-statment for the purposes of complying with homework specifications?
19:11
@MisterMiyagi then how do you get 2, 3, and 4 as a result?
@inspectorG4dget the way I read the question, is that only standard math operators are allowed
Doesn't handle points on either axis
In hindsight this is pretty easy to prove visually. If you watch the gif at en.wikipedia.org/wiki/Cross_product#/media/…, you can see that as the red line sweeps through the unit circle, the pink line moves through all possible directions and magnitudes twice. Except for when red and blue are at a ninety degree angle, in which case pink's direction/magnitude is unique
@Code-Apprentice you add the terms for the other quadrants. e.g. ... + (x < 0) * (y > 0) * 2 + ...
19:14
I can't use comparison operators like > and < — pooya shams 4 mins ago
@MisterMiyagi that's pretty slick. Now do it without comparisons =p
x / abs(x) / 2 + 0.5 is x > 0
Anticipated response from OP: "I can't use piecewise functions such as abs"
differentiable solutions only please
Or, no, that's the wrong word. I'll come back to that joke later.
they already said abs is allowed, but it sure feels like defining a true scotsman.
19:17
@Kevin the OP explicitly stated abs() is allowed
This joke is getting less coherent all the time
@Kevin which word? "piecewise" or "differentiable"?
because I'm overanalyzing your attmpted joke
"differentiable"
The joke doesn't work because abs() is differentiable... Almost everywhere. I guess there's a discontinuity at 0?
that's practically "never"
It is continuous at 0, but not differentiable
so if you interpret "differentiable solutions" as "differentiable everywhere" then it works
19:21
Ok, cool
"differentiable everywhere solutions only please"
well, the proper solutions is of course to just use \Theta(x) and \Theta(y)
I'm not familiar with Theta as a common function name
The Heaviside step function, or the unit step function, usually denoted by H or θ (but sometimes u, 1 or 𝟙), is a discontinuous function, named after Oliver Heaviside (1850–1925), whose value is zero for negative arguments and one for positive arguments. It is an example of the general class of step functions, all of which can be represented as linear combinations of translations of this one. The function was originally developed in operational calculus for the solution of differential equations, where it represents a signal that switches on at a specified time and stays switched on indefinitely...
I think I learned that as u(x).
I guess every domain has its own symbol for that.
19:26
Hi, everyone. Does anyone know if there's a MIME type for .url file?
Do 3 - (x//abs(x)+1)//2 - y//abs(y) for optimal readability
now try to use all of = + - * / % () abs
@Code-Apprentice if you just say "differentiable" then I think "differentiable over real numbers" is implied
I imagine arctan2 has an if...so how about arccos or arcsin?
Hard mode:
> What should the result be when the input is (0,0)? – Kevin 16 mins ago
it should be 0. – pooya shams 5 mins ago
So now there are five quadrants
no, that's just the neutral case of no term giving any result
sum is 0 then
19:39
I'm afraid to ask whether (-1, 0) returns 0 or 2 or 3 or 2.5
just don't do his homework for him
Of course. How can I torment OPs by making them realize their assignments have twice as many corner cases as they thought, if I just hand them an implementation? Where's the character building?
nice, thanks
@akinuri What's a .url file?
19:51
Hello
My question is not python related but I'm trying to connect to localhost wamp server from my mobile device and it doesn't work. I've also turned off my firewall.
Could anybody help me out?
Probably not in a python room, im afraid.
I installed 3.7 and 3.8, and now my scripts are saying "unable to create process" when I double click them - has anyone had this issue? All I could find was that you need to have run as admin on the python executable unchecked...and I do.
I'm pondering whether you just asked how to connect to literal localhost (aka 127.0.0.1) from another device.
You'll want to do ipconfig/ifconfig on the server host, then try to connect to the local IP address from your phone. But, the server part is going to be in PHP I guess and then we open a rabbit hole
@MisterMiyagi that's my reading of it
consider me mildly bedazzled
19:57
I conmect to my local ip address already
I'm talking about a local network, not localhost
Yeah sorry thats what i meant to. You mean the ipv4 address right?
Too*
02:00 - 20:0020:00 - 23:00

« first day (3295 days earlier)      last day (1873 days later) »