« first day (3889 days earlier)      last day (1053 days later) » 
00:00 - 17:0017:00 - 21:00

12:47 AM
cabbage
 
 
5 hours later…
5:45 AM
Is it normal to have alot of flags while making an app? Like a flag to know if window is shown, a flag to know if something is inserted onto the widget and so on... Or should I be looking for better ways rather than make flags(which I do not think is there)? Also these flags are used for processing data, they are not just simply created.
 
6:08 AM
@wim what why where?!
wt.. is this 💩
or does this work with non-filesystem files
I want to see everything as a zip :F
 
6:21 AM
Is the mains offline for you guys as well? Does not load the page
 
loads
 
fine for me. was that just a ploy to get me to open main? pah!
 
@CoolCloud maybe you're caching some fastly 💩 from yesterday
control reload, sudo make me sandwich
 
Mmmm seems like only I'm having the issue, chat also seems to be delayed and slow for me
Anyway, is there anyway to get the passed keyword arguments to the function?
Like if I say foo(2,3) anyway to get 2,3 or even foo(one=1,two=2) and get {'one':1,'two':2} ?
 
if i had to guess, probably yes, but that this also sounds xy
did you write the code of the function? if yes, you could make use of *args, and **kwargs and just have it bundle itself up for you
 
6:34 AM
@ParitoshSingh Well I just want to make sure all the passed arguments to the functions are of the type I want, so that later when some other type is passed, it does not waste time by creating the class and later show the error.
@ParitoshSingh I already have alot of default args specified, so kwargs seems unlikely to be used
 
hm. well you can access locals() inside the function to access all local vars.
im still not sure whether this is ideal or not, to me it seems like you should still just use *args
(but i might be mistaken since i dont know what your function does exactly)
 
@ParitoshSingh This will do it, thanks mate :)
 
no oneboxing of tweets?!
@CoolCloud fastly
 
fastly is still having issues?
 
well, could have issues for cool cloud
 
6:41 AM
Hmmmm its okay now, hope it does not target me again :P
 
6:59 AM
I am too dumb to get this working...
CMD $JBOSS_HOME/bin/standalone.sh -b 0.0.0.0 -Denvironment.config.identifier="${environment.config.identifier}"

results in
/bin/sh: 1: Bad substitution

what am I missing?
 
does "${environment.config.identifier}" need to be `${environment.config.identifier}` instead?
with backticks instead of quotes?
 
even without the quote marks it doesnt work
let me test backticks ...
 
sorry if that doesn't work, my bash is a bit rusty
 
BACKTICKS IT IS!
Thanks man!
the hell i couldnt find anything about substituion online, everyone just said ${} ...
u saved my day man
 
7:30 AM
hey guys when installing a library with pip i keep receiving an error that it cannot find 'io.h' I have been looking all over the internet have installed microsoft build tools and yet still cannot figure why this is... anybody have any idea
 
@Kwsswart Are you using a beta or an alpha python?
Just for reference - pip install in a developer command prompt. Probably it looks for some system header and can't find it. Running in developer command prompt sometimes solves this issue
 
7:47 AM
Only for those who are interested in code reviewing. :-)
https://codereview.stackexchange.com/q/262835/111092
 
You can save two lines by doing blue, green, red = data[i, j]. The 2nd row = [] is pointless. Your comments are pretty pointless as well.
# gray = 0.114 blue + 0.587 green + 0.299 red
Yeah, we can see the formula you're using. What's the point of repeating it in a comment?
# creating a raw 3x2 array of pixel
Instead of explaining that, why not just format your array as a 3x2 shape?
data = np.array([
    [[255, 0, 0],     [0, 255, 0],     [0, 0, 255]],
    [  [0, 0, 0], [128, 128, 128], [255, 255, 255]]
], dtype=np.uint8)
@TheShortestMustacheTheorem ^
 
@0x45 that just hides the error; you can't have environment variables with dots in them in the shell
 
Also, you shouldn't hard-code the dimensions of the input image into your range(3) and range(2) calls
 
@Aran-Fey The comments were there before I typed the code that follows. I copied from OpenCV site. I left the comments for no reason.
@Aran-Fey Yes. I don't know to extract the dimension. :-)
 
8:04 AM
Then you should find out. Googling things is a key skill for programmers.
 
@ShreyanAvigyan I am runnning it within the x64 Native Tools Command Prompt for VS 2019
 
@TheShortestMustacheTheorem if you are using numpy, would it not be a lot faster to use its native operations rather than copy out the individual numbers to a Python array and then only convert it to a numpy array as an afterthought?
 
@Kwsswart Which library are you trying to install? (I can try to reproduce the error.)
 
@tripleee The problem is, I have no enough knowledge to use numpy. :-)
 
@Kwsswart Use Developer Command Prompt for VS 2019. If you're running 64 bit python then you can run vcvars64.bat (abs path depends on where you installed it) in the Developer Command Prompt. (I followed these steps to resolve a similar issue a long time ago and the steps worked back then.)
 
8:25 AM
@ShreyanAvigyan postal its a long winded error to reproduce essentially following with github.com/openvenues/pypostal/pull/39/files
 
@Kwsswart So it mixes up Msys2 and Windows SDK? Or does it provide steps for Msys2 and also for Windows SDK?
So it says to installs libpostal via Msys2 and then install pypostal via Windows SDK, right?
 
@ShreyanAvigyan curious not sure i understood
 
@Kwsswart There are a lot of command prompts installed while installing Visual Studio. One of them is Developer Command Prompt. If you're running a 64-bit python then run vcvars64.bat in the Developer Command Prompt.
Then run pip install postal
 
8:51 AM
Just ran this and still running into the same problem cant get around it when running postal or when running:
pip install postal --global-option=build_ext --global-option="-IC:\msys64\home\user\libpostal\headers" --global-option="-LC:\msys64\home\user\libpostal
 
9:10 AM
Is there anything that actually triggers error when wrong type of objects are passed as arguments for functions?
 
yeah, mypy
or if you write type inspection at runtime by hand
 
I am actually having trouble doing it manually. Is there any rule of thumb or something? Or a general way?
 
the general rule is to not do it by hand, it's unpythonic. if you want to assert types, use mypy
 
Okay then, Ill read more about it. Thanks :D
 
if not (type(arg) == list):  # code smell
    raise TypeError("I wish I were using a statically typed language =(")
@CoolCloud good luck, I'll see if I have a good typing introduction in my haystack somewhere today..
 
9:19 AM
@Kwsswart Then you have to add the Microsoft header files manually to the INCLUDE env variable
And I guess the reason the error is occurring is because they are mixing up msys2 and Windows SDK. These two are different from each other and if anyone mixes these two, well more errors. There are ways to bypass this. But these errors are different on each system. So I can't help you beyond this. Sorry.
Some have libpostal/libpostal.h not found error while others have other errors
 
9:39 AM
re typing checks, if you need to check, also prefer isinstance over type. isinstance allows subclasses to be valid types as well.
 
@ParitoshSingh Yea I realized that after sometime only
I ended up doing in manually for now, I will look into using a module soon
 
Cbg-ning
 
quick question: I have a list like this [5,4,3,2,1,5,4,3,2,10,10]
the question is find only one integer that appears an odd number of times.
I found a solution a bit tedious but that's work and one mate gave me this
def find_it(seq):
    return [x for x in seq if seq.count(x) % 2][0]
I'm quite confused as the count state does not seem to be stored anywhere and yet, the code is doing what it should. Any idea on the reason, pls?
 
first things first, thats a bad algorithm
 
9:48 AM
This is my solution
 
also, why does the count state need to be stored? to answer the question, the .count counts the state (thats an O(n) operation) and it's immediately checked using an if
 
def find_it(liste):
    """first loop
    count all the values and put them in a
    dictionnary, ex: 1:5
    """
    other_liste = {}
    for value in liste:
        if not value in other_liste:
            other_liste[value] = 1
        else:
            other_liste[value] += 1
    """second loop
    check the count value in dictionnary.
    if count value has a remain after % by 2
    it returns the value
    """
    for other_value in other_liste:
        if other_liste[other_value]%2:
            return other_value
 
so, because you immediately check the state after calculating it, you no longer need to store it
your solution is better. do you know why? (hint: what's the time complexity of your friend's solution?)
Now, having said that, this kind of operation is so common that python actually has a builtin for this, called Counter in collections module
other_liste is not a good name for a dictionary
 
@ParitoshSingh didn't know that. Cheers.
@ParitoshSingh I stored the data?
 
that message was a continuation of my explanation of your friend's code.
 
9:53 AM
@ShreyanAvigyan hmmm will try see how to do this
 
@ParitoshSingh ok
 
ie, it's the first code snippet that immediately checks the state after calculating it. so it doesnt need storing
 
@ParitoshSingh I know, I could find better
 
do you know the time complexity of both codes?
 
@ParitoshSingh did not try to see how fast they were working, actually but I can have a test, actually.
 
9:54 AM
you can test it to see, sure. though you wont see the difference properly in small lists, you'd have to use larger lists to see the impact. however, time complexity can be calculated by just reading the code also
 
@ParitoshSingh Does it take time to study that(is it easy, for beginners)?
 
@CoolCloud hm, it's easy once you study it. :P but it's so fundamental to writing good code that i'd recommend everyone get familiar with it, no exceptions.
 
@Arne I did some reading and realized that mypy shows the error only when we use mypy app.py, what if I wanted to run the app and then get the error shown, i.e., at runtime?
@ParitoshSingh Yea I hope on getting over with it soon :D
 
also, it is fairly intuitive too, not too bad for the simple scenarios. we can observe the impact of time complexity in our day to day lives too somewhat
 
@CoolCloud There is a way we can run mypy at runtime only for one file (app.py in this case). Add the following at the end of the file and mypy will check app.py at runtime -
from mypy.__main__ import console_entry
console_entry()
 
10:07 AM
Wow, importing from a __main__.py? Don't tell me that's actually how they recommend doing it
 
No they don't recommend it. It's kind of a hacky way. But this works well.
 
I'd use subprocess.run([sys.executable, '-m', 'mypy', __file__])
 
@Aran-Fey I have a hunch that what they recommend is... different.
 
I would hope so, but I don't have much faith in mypy... or anything in general
 
Who checks mypy's typing? There are type annotations all over the mypy source code.
I found even a better way to run mypy at runtime (they recommend it! it's an api!) -
 
10:18 AM
Mmmmm so will it be fine if I do type inspection during run time manually? It seems to work so far.
 
from mypy.api import run
run()
 
Hmmmhmm? TypeError: run() missing required argument 'args' (pos 1)
 
Oh no I missed a detail. Here's the correct source code -
from mypy.api import run
run(__file__)
 
Did you try it out? TypeError: list object expected; got str
I think it requires something like sys.argv[1:] to be passed in..
Anyway could anyone take a look at this manual runtime type inspection and let me know? dpaste.org/auY2. Type checking is at line 270
 
Ah little more digging tells we need to pass in the [__file__] instead of __file__ and then print the result returned as a list.
 
10:40 AM
"Digging", aka reading the documentation.
 
@ShreyanAvigyan They don't recommend it for what is being discussed here. mypy.api.run is part of the APIs for extending and integrating mypy – for example into another static verification tools. That's miles away from using mypy to self-check a regular program.
 
@CoolCloud There are multiple problems with that. First, locals() includes self, so you have a reference cycle. Storing that as an attribute just so you can access it in type_check is also bad; function arguments exist for a reason. And as others have said, doing type checking is unpythonic. I wouldn't do it unless I often accidentally pass in wrong types for some reason, and then I would do it with assert statements
 
"it's written somewhere" isn't the same as "it's recommended for this".
 
@MisterMiyagi Ah I see.
 
@Aran-Fey Hmmmm I will define a parameter then. Anyway to get over the first problem? Or do you have any other approach in mind?
 
10:48 AM
del self.args['self']
...but make a copy of locals() first
 
So args = locals(); del args['self']?
I did think of passing it as an argument first, no idea why I did not proceed with that :/
 
args = dict(locals()); del args['self']
 
But locals() is already a dictionary right? Looking into it, I get this NOTE: Whether or not updates to this dictionary will affect name lookups in the local scope and vice-versa is *implementation dependent* and not covered by any backwards compatibility guarantees. So that is why we again use dict on it to make a copy?
 
hello i just joined.
 
Yeah.
 
10:55 AM
Okays, thanks mate :D
@sub2nullexception Hi
 
nice so i help people here?
is there an age limit for stackoverflow?
can we chat off topic?
 
I guess I should elaborate a bit on the statement that "type checking is unpythonic". While yes, type checking is rarely done in python, having good error messages is a good design goal. So type checking for the purpose of throwing a nice error is not a bad move.
 
what terms the word "unpythonic"
is that an algorithm or a function can be easily done by an inbuilt method or does it mean the opposite
 
@Aran-Fey Oh that makes it clear. I could get rid of type checking here and the code would work good, but at some point there would be an error that is hard to debug, so I thought why not just show it at the start
 
how many people are there online?
im just really excited.
 
11:01 AM
@sub2nullexception the terms of service require you to be 13 years of age IIRC
 
cool i am 13 !
 
Well you can spend the next 5 mins reading from the RHS about the status of users in the room :P
 
oh nice!
 
@sub2nullexception and the next two googling common words
 
well that is a fun way to sum it up
 
11:02 AM
 
@sub2nullexception That's pretty difficult to define. Sometimes it refers to code that can be written more easily with the use of builtin/stdlib functions, sure. But it can also refer to things that most python programmers simply don't do. For example, Yoda conditions. Writing if 3 == x: may be good C programming, but python programmers will look at you like you're an alien if you do that.
 
@Aran-Fey That clears it up! thank you, many people were using that word in stackoverflow questions
I have a question.
In Python, can you get whether a string is in double quotes or single?
everytime i tried it eventually turned it to single quote.
 
No, because it doesn't matter.
 
if you have access to the source where the string was defined, you can parse it and find out
 
11:05 AM
The quotes aren't part of the string. They're only part of the code.
 
hmm.
well that is interesting.
 
and it's not "turned into" a single quote so much as represented as a single quote when you ask Python to print it out
 
thanks for correcting me
does anyone moderate this server?
i mean chat room
 
the regular Stack Overflow moderators moderate chat too; in addition, each room has a number of room owners with privileges above those of individual users
 
11:08 AM
>>> str = "moo  bar"
>>> str
'moo\tbar'
the character after "moo" is not "turned into" \t, it is still a literal tab, but it's represented in this way so that you can unambiguously understand what you are looking at
 
yes. i use it to see value types on a daily basis to debug code.
wow you seem to have a lot of reputation
 
well that's basically what's happening with the double quotes, too
 
are you professional?
@tripleee yes i see the point
 
I work in the tech industry yes, though I would not call myself a Python expert in particular
 
yeah, nobody would be considered absolute "god" at a language except the creator.
What languages you work with?
 
11:16 AM
I used to work in Perl for many years but I haven't really looked back after switching to Python; also shell script and related DSLs like Awk and sed, Emacs Lisp when I can ... right now trying to figure out a cython module but not really getting anywhere
 
@CoolCloud Consider that there is an infinite amount of ways people can misuse your API. Types capture only a tiny fraction of that; e.g. side="Kevin" would not get caught. Yet even just the naive checks you have add a lot of code to maintain and run, without actually covering most possible errors. Try and be mindful of whether type validation actually helps in practice; it's often useful to add them after your code has been used and you know common issues.
 
11:39 AM
does somebody know if amateur astronomers can see galaxies? Like I checked out this article: astronomy.com/magazine/observing/2019/02/… But somehow I feel like all the images are from hubble and not amateurs. Is it even possible to view galaxies from earth? Where is andras when one needs him. Where is he in general? It's been a while
 
his last message was an hour back, but yes I seem to notice less of him recently
 
Maybe the Eternal September got him :)
 
@CoolCloud why run it at runtime? only push / execute code that passed mypy first, then you don't need to think about differences to runtime, because there aren't any.
only reason to run mypy during runtime that I can see is if you generate or somehow receive new code during runtime and want to test that. which is a whole 'nother issue, but at least a legit use case
 
12:05 PM
@Hakaishin twitter.com/quarkmarc/status/1347339980729765891 i liked this tweet recently, apparently his tech hardware stack here is "Sony a7 looking through a Celestron 925 edge hd on a cgx mount."
 
@PIngu wow this is so mindblowing. I gotta really get into astronomy some time. You can see freaking galaxies from earth How cool is that :D
 
@CoolCloud and if a client sends you bad data your framework can hopefully figure out which 4xx it needs to send back without you needing to do anything
 
apart from the Milky Way, the Magellanic clouds are plainly visible to the clear eye; Andromeda is also visible, though it looks basically like a smudge without binoculars iflscience.com/space/…
 
@tripleee woooooooooooooooah, that image is beautiful, who knew that andromeda is this big. It would be so epic if we could see all the galaxies like in that image.
 
12:28 PM
@MisterMiyagi Well side='kevin' will be caught later on, not initially though
@Arne Hmmm I see
 
Galaxies: they're pretty big
 
TypeError: 'zip' object is not reversible There goes my code golfing...
How to get the second/last element of a zip without storing the intermediate result or using a list?
 
reversed() needs an optional "yes, even if the iterable is infinite, try to reverse it anyway" parameter
 
golfing? perhaps skip the zip, take the last item of whatever youre doing by hand
(ps, i have no context atm. recbg)
 
@MisterMiyagi So you're suggesting to avoid type checking for now?
 
12:34 PM
@CoolCloud well, technically you know the use case best. if there's a clear benefit to it, and you think it deserves to be there, then go for it.
generally, it really depends from case to case. sometimes, what's more useful than a type hint is a more restrictive check, for cases where your input must be one of "blah blah blah" for example.
in other words, assess which checks are "easy wins that should be used", and dont be focused too much on type hints for the sake of type hints.
 
Here its user dependent, the user should prolly figure out that side accepts strings and not numbers or bool
So I guess I'll not use this in the first initial version and wait and see for response and slowly think about using it :D
 
@CoolCloud General runtime type checking, yes.
 
yes. thing is, you can keep adding defensive checks forever if you wanted to, it's useful to remember YAGNI. If you have evidence for what checks are necessary, you're in a much better position to add them in
3
 
Static type checking, no. Use it when you don't mind the typing.
 
Speaking as a half-clueless user, when documenting your public API, please indicate the types of all arguments
 
12:38 PM
yeah. runtime checks* shouldn't be a substitute for documentation (i guess type hints effectively become documentation in just about any useful framework that exists)
 
Well can this be called an API, its more like a custom widget to be used or so..
 
"Surely even my dimmest customers can figure out that num_spokes is an int just from the name" -- sorry, please lower your expectations of me :3
 
As a rule of thumb, don't try to defend against the user not reading obvious documentation.
If they are that far, you won't anticipate their error anyway.
 
Okays, that makes things more clear. Thanks for helping out guys :)
 
@CoolCloud I guess when I say "API" I really just mean "the parts of the project that another person might use one day"
It's a "you know it when you see it" quality
 
12:42 PM
Ah, I see. I got a lot to learn and understand
 
.. do you provide documentation to your users?
 
I have not released any reusable code to the public yet, though if I plan on releasing. I obviously will.
 
"users" doesnt need to mean general public
who are you writing these codes and checks for?
 
users
 
are they programmers? ie importing your codes to use them? or how are they using your codes
 
12:47 PM
They copy it from an answer I wrote that they found via google ;-)
 
Yea they are prolly programmers, who will import my code and then use them.
 
okay, so you're at that stage essentially providing people an API. an API doesn't have to be something special, it can be as simple as giving people some stuff to import. aka all libraries are apis for example, we import and use the functions they provide to do some task.
so, at that point, anyone importing your code only knows information from the documentation you provide for your functions/classes. so, good docstrings will go a long way.
and then, ideally a proper documentation can help too (this can be autogenerated from your docstrings as well, though i will admit this is something ive never used yet)
So yeah, main takeaway, if you havent yet, atleast make sure you write good docstrings for every single class/function that people are expected to use directly
(this also applies to colleagues working on the same codebase within the same team. if they're using stuff you write, you should help them out with good docstrings. unless you hate them for some reason. which is perfectly fair if that's the case)
 
I will keep this in mind, thanks :-)
 
1:13 PM
Hello
Is that an alternative to having 1000 comments under a question on stackoverflow ?
 
As in, "does this chat room exist so you can give long technical explanations of things without having to break it up into tiny comments on the main site?"? Sure, that's one of our many uses
 
1:30 PM
I think I found a better approach to the nested parens puzzle I asked about yesterday... You can use a Divide and Conquer approach if you define an "off-by-N balanced string" as "a string that could be balanced if you added N right parens to the end"
Then you can define recursive qualities like "the number of perfect balanced strings of width 50 is equal to sum(number of off-by-X strings of width 25, times the number of off-by-50-minus-X strings of width 25, for all values of X in the range (0, 50)"
(Not sure if that's a correct definition, but you get the idea)
My preliminary results have a lot in common with Pascal's Triangle, which is an encouraging sign that I'm in the right conceptual area, since Pascal's Triangle and binomial coefficients and the catalan numbers and Dyck words and balanced parens are all related
 
@Kevin you assume a lot :)
then combinatorics was never too interesting to me
 
1:50 PM
I think combinatorics can look quite intimidating because it requires 1) a lot of confidence in your understanding of recursion; 2) a very careful definition of exactly what you are trying to accomplish. Which just happen to be two of the rarest resources in our profession
 
hey! don't hate on combinatorics. That's a branch of math you can really count on
 
hehe
 
badum-pshh
 
takes a bow
 
MrG4dget, are you doing your PhD in Mathematics?
Could you list me some nice books for permutation-combination...
I once went for Tarasov, for probability, but found it too tough. It was very good for calculus, though
 
1:59 PM
Applied Combinatorics: https://www.appliedcombinatorics.org/appcomb/
Combinatorial Algorithms: https://www.routledge.com/Combinatorial-Algorithms-Generation-Enumeration-and-Search/Kreher-Stinson/p/book/9780367400156
 
Question can we see any source code of libraries on pypi ? if so how ? trying to understand the code more about how it works and want to view it on github to read through it
 
Many pypi packages link to github as their homepage.
 
download it and look at it, a python package is just a zip
 
Otherwise, Google is your Friend.
 
oh yeah, if they link their github that's of course the best
 
2:05 PM
@inspectorG4dget Thank you very much!! Combinatorial Algorithms book is awesome :)
 
@lmao cheers! that has a lot on generating permutations and combinations
 
@Kevin precision and recursion uff :D
 
@inspectorG4dget Yes, plus it is dealing a lot in Data Structures, am going to have a busy week :D
 
now I'm curious: what are you working on?
 
Maybe my infectious enthusiasm just has them hyped for combinatorics in general
 
2:13 PM
I want to master probability but P&C takes me down
 
does anyone have a dupe target for "keep asking the user for input until a valid input is entered"? This needs a dupe hammer: stackoverflow.com/q/67905845/198633
P&C are fun. I can probably field a few very specific questions before I get back to mah jerb
 
The balanced parens puzzle I'm working on is actually a simplified XY problem. My upper level question is: If I have a context free grammar, how hard is it to generate all strings in the language that have exactly N characters?
 
"P&C are fun" - Not for me, most dreaded things I ever encountered,
 
@Kevin is this for some sort of fuzz testing?
 
I've been oscillating between "it's always possible for any CFG, and it's even fairly straightforward to write a general string generator generator that takes a CFG and returns a string generator", and "it's sometimes possible, and there is a straightforward way to determine which CFGs are cooperative" and "it's undecidable, everything is undecidable, we're doomed"
@inspectorG4dget If I go up the XY problem chain four more times, the uppermost problem is "how do I print Hello World in an interesting way?". Not a joke.
 
2:22 PM
I don't really think it's undecidable. I think it's a graph exploration problem. And given the fixed-length constraint, you should be on pretty solid ground
 
@Kevin Seeing how difficult parsing is, I guess "hard" might be an understatement for your problem.
 
Cheers guys
 
Peter Linz - "For any context-free language L, there exists an npda"
 
@MisterMiyagi Maybe. In a sense, generating a string from a grammar is the opposite of parsing a string with a grammar. And some mega-hard problems are trivially easy in the other direction. Encryption is easy, cracking encryption is hard. evaluating a binary expression with known values is easy, solving 3SAT is hard. Hashing a string is easy, unhashing a string is impossible.
 
Come to think of it, bottom-up generation is probably a bit simpler than top-down generation. For parsing it is simpler but comes with a hefty space complexity – which doesn't matter for generation.
 
2:30 PM
Sorry for interrupting. Only for those who are interested in solving puzzles. It might be time consuming. :-)

What causes the different result in calculating `grayed` (that calculated with dot product) and `comparator` (calculated by `cvtColor`) for the following? :-(


import cv2
import numpy as np


data = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]], [
[0, 0, 0], [128, 128, 128], [255, 255, 255], ]], dtype=np.uint8)


coefficients = np.array([0.114, 0.587, 0.299])

grayed = (data @ coefficients).astype(np.uint8)
 
Maybe you should read on how to format code in chat sopython.com/wiki/…
 
Could anyone explain to me this line? I am not familiar with python, sorry.

>>>np.where(kChannel < 0.9, (1-floatImage[..., 2] - kChannel)/(1 - kChannel), 0)
 
:52380093 You should do all the testing here
 
@CoolCloud: OK. Nice! Thank yoU!
 
does anybody live in british columbia? I'm browsing over it on maps and this things is eeeeempty. Like I've been looking at remote places, but dang I can't find a city :D
Woah it's 25 times bigger than switzerland and has half the population size. I wish switzerland had more space...
 
2:42 PM
I published the repo, would appreciate any contributions :)
 
if not self.hidden: # If window is not hidden phew, glad that comment is there to explain this line ;-)
 
On the bright side, at least that part was readable :P
 
@TheShortestMustacheTheorem My guess is, one rounds up and the other rounds down
 
Off topic here is allowed?
 
Upto a level, I believe yes
 
2:56 PM
@TheShortestMustacheTheorem I think grayed = np.round(data @ coefficients).astype(np.uint8) will match cv2's rounding logic
@butexa Hmm, not sure. If that code is from this question, even knowing the surrounding context doesn't make me confident about what it's doing
I know that a lot of numpy collection types support a kind of "pass through" for scalar arithmetic. In other words, 1 - my_complicated_np_thing is the same as "go through all the elements of my complicated np thing, and replace the value with 1 - the_value"
So (1-floatImage[..., 2] - kChannel)/(1 - kChannel) is something like "go through all the elements of kChannel and floatImage[..., 2] in tandem, and calculate (1 - f - k)/(1 - k) for all of them"
Ah, it's converting from RGB to CMYK. That makes things easier. You just need to define a formula like this one:
float get_cyan(float r, float g, float b){ //all arguments must be between 0 and 1
    float k = 1 - max(r, g, b);
    return (1-r-k) / (1-k);
}
And iterate over all the pixels of your input image, call this function on it, and store the result in your cChannel collection.
 
3:20 PM
@Kevin Excellent. Thank you very much!!!!!! :-)
 
Here's a contrived example of a CFG that a string generator generator algorithm might choke on: S := S S | <empty string>. A particularly naive algorithm might convert that into the following code:
def generate_strings():
    for x in generate_strings():
        for y in generate_strings():
            yield x + y
    yield ""
This will recurse forever without ever yielding a value. This is silly, because we smart humans can easily determine exactly what set of strings match the grammar: it's the empty string and that's it. Unfortunately, there are an infinite number of ASTs that the grammar can use to represent that string, so it never gets around to finishing any of them.
A less naive algorithm might notice that the grammar is equivalent to S := <empty string> | S S, and move the yield "" to the top of the function. Now it will at least yield values at a reasonable rate, although it's still going to run forever.
 
I might be overburdened but, I expected the my_dict dictionary to have the corresponding number of 'Child'. Why are the lists being shared if I'm accessing with the correct key?

people = {
'John': 1,
'George': 2,
'Maria': 3,
}

my_dict = dict.fromkeys(people, [])
for name in people:
  n_child = people[name]
  for i in range(n_child):
    my_dict[name].append('Child')

for key in my_dict:
   print('key = ', key)
   print(my_dict[key])
   print()
 
you assigned the same list to every key
 
Yeah, it's not advisable to use a mutable object as the second argument of fromkeys
Consider using a collection.defaultdict(list) instead, which will create unique list instances for your pairs, as desired
 
3:36 PM
Why passing copy.deepcopy([]) does not work in the second argument? That crossed my mind and I tested with a deepcopy to avoid that but it did not work either
 
It deepcopies the list, but then it uses that single result three times
 
Ohh, I see
Thank you
 
is it wrong if I say username checks out :p
 
It was definitely intended as such, lol
 
Oh also you could possibly do this without a defaultdict, and just work directly with a dict comprehension:
>>> {k: ["Child"]*v for k,v in people.items()}
{'John': ['Child'], 'George': ['Child', 'Child'], 'Maria': ['Child', 'Child', 'Child']}
I didn't suggest that first because it's only feasible if you're not doing any other interesting work inside your for loops. Your toy code isn't, but your real code might be
 
3:45 PM
Emptiness of CFG : Remove all the useless symbol.
Since 'S' is generating empty string, it is also useless.
Now, if the start symbol (S) itself is empty, the grammar generates an empty language.
 
Yes, that sounds logical. What about the general case? If a CFG contains an empty string in some of its rules, is it always possible to convert it into a CFG that does not use any empty strings?
You can't just delete all rules that mention empty strings at all -- for example, the CFG s := <empty> | 'A' s 'B' is very different from the CFG s := 'A' s 'B'
So there needs to be some kind of substitution logic
 
Yes, there is an algo for removing emptiness.
 
I suspect this problem becomes easier if you require every rule to contain at most two symbols, even if this requires you to introduce many more nonterminals
 
You keep on removing the useless symbols.
If, by chance you find the start symbol itself useless, then the language is empty.
That is why deciding a CFL being an empty one is a Decidable thing.
 
@Kevin thank you so much! What about np.max with axis=2? I am not sure I am converting the code the right way because I don't know anything about python
 
3:57 PM
@lmao Ok, let's try doing that on the example. Which useless symbol should i remove from s := <empty> | 'A' s 'B'?
Keeping in mind that s := 'A' s 'B' is an invalid solution, and you can't get to s := 'AB' | 'A' s 'B' without removing a symbol and also adding a symbol
 
LOL, i am very junior to you, as well as very less at intelligence compared to you, so pardon me for asking following silly questions
is your grammar like: S-> empty/A+B ??
The only useless symbol that is removed is on the left hand side
 
I'm sorry if I got a little too confrontational there. I like to ask for concrete examples because sometimes it's hard to work out the logic without them
 
no, no that's ok, i am just trying to say that i might not even get what you are asking( I know you are way too much intelligent, i have known it for past 2 years)
I have a lot of respect for you
 
@butexa Looks like np.max(floatImage, axis=2) finds the maximum channel of each "pixel" in floatImage -- since floatImage is a w*h*3 matrix, numpy needs axis=2 to understand that it should only be comparing values among the R/G/B triples
 
I have read Peter-linz and Cohen, in those I read about these algo for determining whether a cfg is empyt or not
 
4:05 PM
If you used axis=1, I guess it would find the maximum value in each column of the image, and axis=0 would find the maximum value in each row. Not very useful for our purposes
 
and they suggest this algo for that
 
@Kevin so I should have it done correctly. In the get_cyan function there is max(r ,g, b); I guess simply return the max between these 3
 
@lmao I see. It does seem like a good approach for finding whether a CFG is empty. But I think I'm trying to find something slightly different... I will try to think of a way to restate my goal.
@butexa Yeah.
 
s := <empty> | 'A' s 'B'?
Considering Computational theory, here, A and B are Non-terminals, and since they are not deriving any thing 'S' is useless, and hence it is an empty CFL
 
Hmm, I didn't intend for the CFL to be empty... I wanted it to match any string like "AB", "AABB", "AAABBBB", etc
 
4:12 PM
If grammar is :
s := <empty> | a s b? and a,b are terminals , then definitely your cfl is not empty as you could derive strings
 
ok, makes sense. Or, hmm
We might have different notation for grammars. I consider 'A' and 'B' to be terminals because they have quote marks, and a and b and s are nonterminals because they don't have quote marks
 
If you consider 'A' and 'B' to be terminals then:
Your grammar is generating string with terminals A and B, and definitely not empty
 
Ok, now it makes sense
 
Sorry for interrupting. Folks, how to generate a random array with 3 elements, each element must be between 0 and 1 (inclusive) and the sum of these 3 elements must be exactly equal to 1.

I want to use this array as a coefficient for converting color BGR to Gray.
 
Progress!
 
4:16 PM
Useless symbol - Those which appear on only on the left hand side and do not derive anything
@Kevin Nice :)
 
I want to replace this coefficients = np.array([0.114, 0.587, 0.299]) randomly.
 
Ok, any restrictions you have in mind? I notice all the numbers are between 0 and 1, and they add up to 1 (I think).
Do we care about either of those properties or can we just go hog wild
 
I did with Mathematica.
@Kevin 3 numbers, each between 0 and 1 inclusive will add up between 0 and 3 inclusive.
I cannot find any functions in python for partitioning an integer.
 
4:33 PM
I'm tempted to suggest coefficients = np.array([random.rand() for i in range(3)]) but I'm wary of using rand() more than once in a formula without thinking about distribution curves
It's probably not a big deal if you're just doing this so you can manually inspect just a few random test cases.
If you're asking "do I need to download another package to use random?", then no, it's a built-in module. If you're asking "should I find a third-party package that has more sophisticated random number generation?", I think that might be overkill... If you have a clear idea of what kind of distribution you want your results to have, then you should be able to build any generator you need using the tools in random
If the distribution you want is "I don't care, because I just want to eyeball some test cases", then regular rand() will suffice
 
import numpy as np


coeff = np.array([np.random.rand() for i in range(3)])
coeff = coeff/sum(coeff)

print(coeff)
print(sum(coeff))
 
en.wikipedia.org/wiki/Bertrand_paradox_(probability) is an interesting illustration of how results can differ based on your algorithm, even if all of them use the same underlying RNG calls
 
@Kevin: OK. Thank you very much for your time.
I am wondering, whether there is a better way to normalized the coeff. My coeff = coeff/sum(coeff) is ok?
 
00:00 - 17:0017:00 - 21:00

« first day (3889 days earlier)      last day (1053 days later) »