« first day (3291 days earlier)      last day (1656 days later) » 

12:23 AM
@Simon I'm inclined to leave it open. True, the OP is asking about converting their code to C, but IMHO that's just an XY problem. Someone familiar with that technology might see a simple flaw in the OP's code that causes the slow speed, or tell them that the delay is unavoidable.
 
 
3 hours later…
3:04 AM
I thought about it and I think I got the error because x is a local variable for the function and for the nested function,it can only read value of x but not change it.
I am gonna search up more on this though
 
3:25 AM
Ok I have a question for ya'll. Im creating a BBS style RPG game where by the user can choose to be 1 of 3 classes. Each class is assigned a variable (Bar_Str_Val, Wiz_Str_Val, or Rog_Str_Val). How do i assign each to a single variable depending on what the user chooses?
 
 
1 hour later…
4:45 AM
@JonClements I know this is late, but I'm sorry to see you resign. You have always been a voice of reason and one of precious few who made room 6 more pleasant and welcoming, and it is going to be a challenge moving forward without your guiding hand. I hope you'll pop in from time to time. Don't be a stranger please :)
 
 
1 hour later…
user3064538
5:53 AM
I'm trying to update this question to link and copy the Python 3 documentation but it's saying that I can't have a question with that title because it's a bad one stackoverflow.com/questions/17330160/…
 
6:32 AM
@Gehn47 I don't understand the question. If you already have 3 variables, what does "assign each to a single variable depending on what the user chooses" mean?
 
 
2 hours later…
8:20 AM
@Boris false positive on a newer crap filter
I don't know if mods can edit in spite of it. I'd hate to retitle something like that
 
8:33 AM
I am hoping you can guide me re. Case 3 from the following link. The author says in Case 3 that solution one (using -m) is not possible. Can you advise me if this is true? chrisyeh96.github.io/2017/08/08/…
Case 3 can be seen if you scroll up a bit after click in the above link
 
That whole article is confusing, and I'm not convinced that the author knows what they're doing
"assume that foo.py is only ever run directly, never imported" Why would I assume that?
TL;DR:
1. Create a package/module that contains all your library code (code that's meant to be imported, not run)
2. Place all files that are meant to be run *outside* of said package
3. Install your package
 
9:35 AM
In a shared library (hosted on pypi), if logging is done using root logger, then is it possible for the calling application to set custom handler for the library?
 
whats upppp
 
 
3 hours later…
12:18 PM
Revisiting OAuth2 again... some APIs (dropbox, google drive, ...) give me a client_secret when I register my app, while others (YandexDisk, idrive, ...) only give me a client_id. The program I'm writing is a "public client", i.e. it can't keep these credentials secret. Is there any way around publishing my client_ids and client_secrets?
According to my research it would've been good practice to ask me whether I want to have a client_secret or not, but 1) some of these APIs didn't ask and 2) I don't see how not giving me a client_secret at all is any safer than giving me a client_secret that I can't keep secret anyway
The worst thing that can happen if I publish these credentials is that someone can use them to write a program that pretends to be my program, right?
 
 
2 hours later…
2:23 PM
Can github show the outputs of a .ipython file?
If I edit a ipython file in my laptop and then save it(after executing the outputs), are the outputs also get saved in the file?
 
3:01 PM
@Quark I don't think ipython files work that way (I may be wrong). I think you need to use the appropriate editor which automatically saves the interactive session's inputs & outputs.
(I'm assuming you meant manually editing the ipython file in some text editor)
 
3:33 PM
@Quark I would create a private (or even public) repo and test it with a simple "Hello, World!" but IIRC, github has a notebook rendering mechanism and it will render the output.
for instance see this ipynb.
 
cbg
Me reading this answer: Jokes on them, 'cause I already forgot too much python to participate on SO anyway. :P
 
Is there a simple way to apply numpy.random.choice to multiple ps?
 
@user76284 What do you mean? A two dimensional array of ps instead of 1?
 
Yes. Sampling from multiple categorical distributions at the same time.
There's probably a clever way to do it with cumulative sums.
 
3:46 PM
Does changing the output shape work? This can be done with the size argument.
 
I think the problem with that is the ps are different. It's not one categorical distribution (i.e. one p) being sampled multiple times, but sampling once from multiple categorical distributions.
i.e. one sample from multiple categoricals, not multiple samples from one categorical
 
From what I understand the `p` can be subdivided into segments: so (not using Python notation):

p=[dist_one ; dist_two ; dist_three]

But if this isn't correct, I'm not sure what to do, sorry. best of luck. rbrb.
 
I think (p.cumsum(1) - np.random.uniform(size=(len(p), 1)) >= 0).argmax(1) might work.
 
@user76284 I don't understand what you're trying to do
 
Take one sample from each of multiple categorical distributions.
 
3:56 PM
Is this equivalent to multiple calls to choice with various constant ps?
can you give an actual example?
 
Yes, it's equivalent to [np.random.choice(len(p), p=p) for p in ps].
 
But choice called with a scalar p is just uniform sampling, right?
 
ps is a 2D array.
Each row, i.e. each p, is a 1D array.
 
ah
and independently you want to sample with each
 
Yes
 
4:03 PM
okay, thanks
 
Ok, what I suggested seems to work.
 
@user76284 I suspect you'd need uniform(size=p.shape) for independent sampling
Wouldn't your rows otherwise be correlated?
 
Yeah, or rather that should be ps.shape[0].
def categorical(ps):
    return (ps.cumsum(1) - np.random.uniform(size=(ps.shape[0], 1)) >= 0).argmax(1)
 
that's just a different way to say len(ps)
 
Yes
 
4:06 PM
i.e. my question still stands
 
What's your question?
 
1 min ago, by Andras Deak
@user76284 I suspect you'd need uniform(size=p.shape) for independent sampling
1 min ago, by Andras Deak
Wouldn't your rows otherwise be correlated?
 
I don't understand. That's what I did.
 
where did you do that?
 
np.random.uniform(size=(ps.shape[0], 1))
 
4:07 PM
how is size=(ps.shape[0],1) the same as size=ps.shape?
 
Oh, you're suggesting one for each column.
 
If you have two rows in ps that are the same then the corresponding samples would also be the same in the current setup, I think
 
This is getting a single uniform for each row.
 
okay
 
I based it off how one samples from a single categorical distribution.
To sample from [0.2, 0.3, 0.5], for instance, first get the cumulative sums [0.2, 0.5, 1.0]. Then generate a uniform and choose the interval where it lands in.
i.e. choose the index whose entry that is greater than or equal to the uniform variable.
 
4:20 PM
Ah, OK, I missed that you want to end up with ps.shape[0] numbers
 
Yep
I tested my function and the averaged counts of each column agree with the ps.
To good precision.
 
4:34 PM
Yeah, what you have seems reasonable
 
4:46 PM
@user76284 although I'm wondering about edge cases. If the array before .argmax(1) is all False or all True for a given row then you'll always get 0 for that row, right? I'm wondering if that leads to some bias
 
That's a good point. The last column of ps.cumsum(1) is always 1, so there will always be at least one True (the last column).
If it's all True then that just means the first index should be taken since the uniform was less than its value (which represents the upper bound of that interval).
For example, less than 0.2 in the case of [0.2, 0.3, 0.5].
 
Bah, right, I was playing around with a random array. Forgot that you have proper probabilities, sorry.
 
 
1 hour later…
5:55 PM
All, if we fill missing data with the mean from all previous rows, do we call that a 'backward mean' or 'forward mean'? Re this
 
6:33 PM
if we can take a cue from how we use ffill, i think forward mean can work just fine. Having said that, i don't think such a term actually exists
 
 
2 hours later…
8:41 PM
@ParitoshSingh Yes I know such a (standardized) term doesn't exist, that's exactly why I'm asking here (see my comments posted on that question). Would we call it a 'backward mean' (because the computation of mean looks backward, akin to 'LOCF/Last Observation Carried Forward') or 'forward mean' (akin to 'forward fill', because we're filling forward)?
 
I get the error : "int object can not be iterated" how do I resolve this ?
 
@Tanuj you are not calling the method of your custom class. You are calling the built-in function sum
 
that really shouldn't be a class in the first place
 
@AndrasDeak on changing it to sum1 it says sum1 hasn't been defined
 
@Tanuj indeed it hasn't
Have you read a good tutorial yet?
 
8:51 PM
perhaps it's time to (re-)read a tutorial about classes
 
@AndrasDeak what does it mean
 
it means that there's nothing named sum1 in the global namespace
 
Nope , I read one at w3 schools but it didn't help much apparantly
 
that's w3schools for ya
 
Yes, I'd suggest reading a good one. The official one is usually okay docs.python.org/3/tutorial
 
8:52 PM
@AndrasDeak okay ? what does that mean ?
 
there's also some suggestions at sopython.com/wiki/What_tutorial_should_I_read%3F
@Tanuj I think you should first read a decent tutorial, and come back if it's still unclear
without a coherent model of how the language works you'll be stuck every step
 
uhm
I've got a practical tomorrow and I was just looking to make a basic class that had a function to add two numbers
 
Have they taught you things in that class?
 
Why would you make a class for that? That's not what classes are for
 
what are they for ?
I was just doing that as an analogy to C++ and JAVA programs
 
8:55 PM
...what does that "practical" cover exactly?
 
Classes represent objects. That is, things with state. Adding two numbers doesn't require a stateful object.
 
Ah I think I've got it
 
don't go class shaming :P
 
You give it two inputs and get a result - that's what functions are for
 
I didn't use the object of the class to call the function :/
 
8:58 PM
I'm glad it works?
 
Right. And as you can see, ob is completely pointless in that code. You might as well just do d = summ(3,4)
 
@Aran-Fey you can't :P
are you saying it should be a @staticmethod?
 
Remove the class and then do that
 
I take it they wanted to practice classes...somehow
 
@AndrasDeak exactly lol
 
9:00 PM
Probably better to do that where a class actually makes sense
You wouldn't try to do add(1, 2) with add defined in a class if add actually accessed the object somehow
 
I'm just starting learning python in class , can't tell the prof what to teach either
 
I'm curious: were classes the first lesson in python?
 
2nd
 
nice
 
class Player:
    def __init__(self, name, health):
        self.name = named
        self.health = health

    def take_damage(self, dmg):
        self.health -= dmg

player = Player('you', 10)
take_damage(3)  # who's taking damage?
^ that makes no sense, nobody would even think of trying that
 
9:03 PM
Okay, that's not very helpful at this point. We've already covered that they should learn the basics first.
I don't really think this is about classes, because you should start expecting fast that no name comes out of the blue
 
I'm just trying to say that writing a class just for the heck of it doesn't make for good practice
 
though I can't guess how someone might think classes behave if they haven't yet seen one...although I'm pretty sure C++ methods can also only be called within the same class or via an instance or something
@Aran-Fey ah, that's not at all how it came across. It sounded like a (reasonable) point why the original sum1 was a NameError
 
communicating is hard while I'm half asleep
 
>>> jit(lambda x: x**2)(1)
Segmentation fault
something tells me this should not happen
Okay, reinstall helped. Phew!
 
I'm surprised that works. Does it decompile the code object...?
AFAIK there's no way to retrieve the source code in a repl
 
9:12 PM
I bet it does all sorts of black magic, I have no idea
>>> from numba import jit
>>> jit(lambda x: x**2)(1)
1
in case you were wondering what the result was...
 
I - perhaps foolishly - assumed that the result would be correct :P
 
I wouldn't have thought that the usual @jit decorator messes with the source anyway
 
9:46 PM
@Aran-Fey Writing everything in a class, such as writing a staticmethod add() that adds two numbers, is classic Java thinking. This is very likely material developed by someone coming from J-Land.
 
I don't think it's Java, the teacher waited until the second lecture to bring up classes
 
I wonder if there are any Java-in-Python-clothing courses out there telling students that sys.stdout.write is better style than using print. After all it is more object-ey. (And more like System.out.println)
 
how do you interpret this in python from R: for (i in 1:l){if (probs[i] <=f[i]) sig[i] <- 1}
I am thinking I need to use enumerate?
I am not familiar with R but trying to convert an R code to python
 
Something like sig = [probs_element <= f_element for p_element, f_element in zip(probs, f)]
 
I'm guessing that's for i in range(l): if probs[i] <= f[i]: sig[i] = 1
 
9:57 PM
(Guessing that R is one-based indexing, and sig array is initialized to 0's)
 
if <- is asignment then <= should be super duper assignment
 
yes sig is initialized to zero. So you dont think <= means less or equal to 1
 
you tell me, this is the python room
 
less or equal to f[i]
 
No, it means less than or equal to the corresponding element in f
 
9:59 PM
yes
my confusions is that the code is nested within multiple {}
 
It might be easier to follow if you didn't put it all on one line
for (i in 1:l) {
    if (probs[i] <= f[i])
        sig[i] <- 1
}
 
shoot sorry about that
 
I meant "easier for you to follow". Breaking up into lines makes clearer the separation of list iteration and the assignment to sig, apart from {}'s.
 
Oh true
here is the full function
function (pvalue.vec, q)
{
    if (min(pvalue.vec) < 0 || max(pvalue.vec) > 1) {
        stop("p-values not in valid range")
    }
    probs <- sort(pvalue.vec)
    l <- length(pvalue.vec)
    correct <- sum(1/c(1:l))
    fdr <- c(1:l)/l * (q/correct)
    sig <- array(0, c(l))
    for (i in 1:l) {
        if (probs[i] <= fdr[i])
            sig[i] <- 1
    }
    sig <- sig * c(1:l)
    maxsig <- max(sig)
    if (maxsig == 0) {
        thrprob <- 0
    }
    else {
        thrprob <- probs[maxsig]
 
You have 2 minutes to edit that post and convert to code using ^K - please do so
 
10:06 PM
edit
how do I edit?
 
THere is a side menu on the post, select 'edit'
 
Is this better?
 
A bit long, but much easier on the eyes now
 
import pandas as pd
q =0.05
pvals2 =[0.00000295, 0.78497692, 0.67490742, 0.93007279, 0.65885729, 0.00009310, 0.99380176, 0.98943676, 0.01493185, 0.07604793]
pvals = pd.DataFrame(pvals2)
for i in pvals:
    if i < 0 or i >1:
        print('p-values are not in valid range')
#print(pvals)
probs = pvals.sort_values(by=pvals.columns[0])
#print(probs)
l = len(pvals)
#print(l)
ll = list(range(1, l+1))
#print(ll)
d = []
for i in ll:
    d.append(1/i)
correct = sum(d)
#print(correct)
fdr = [i/l * (q/correct) for i in ll]
Thats how far I came
 
Oh, that's clever - assign 1 or 0 to sig, and then multiply each sig value times the corresponding value in c. (By "clever" I meant "annoying" - couldn't we just assign sig[i] <- c[i]?)
So you need to remap some thinking - R appears to use 1-based indexing where Python is 0-based.
 
10:15 PM
well this by no means optimized, just trying to follow the R logic
and yes R uses 0 based indexing
my concern so far is the last bit with enumerate
I think I am extremely off
 
I sense miscommunication
 
Hey @AndrasDeak yes. I am confused I admit
I am just trying to convert an R code to python..not working out well
 
you'd first have to pin down whether R is 1 or 0-indexed
because Paul said it's 1-based and you said "yes, it's 0-based"
 
python is 0 based was what I meant
 
ah
that part we're all aware of here :P
 
10:26 PM
lol
my bad
do you think what I have so far compares?
 
10:43 PM
I took a stab at a line-by-line conversion that you can study -> dpaste.com/1HYQ4WA - I assume there is some global array named c since it is referenced in correct but not defined. In a couple of places I show how you would using integer indexing, which is closer to your R code (or C or Basic or...) followed by another version that just iterates over the sequence, or a zip of two sequences if they must be iterated in corresponding pairs.
If you just iterate over the sequence directly, you don't have to worry about enumerate or 1-base or 0-base.
I may have done more harm than good here, if so, I'm sorry, I was in a hurry.
Must leave now, meeting wife for dinner
 
 
1 hour later…
11:51 PM
Hey folks, I just saw this question and it seems to me like it shouldn't be closed. It's a bit unclear, but that's because OP seems unsure of what they're asking about. To me, it's pretty clear they're asking about modifying an instance variable, and thus pretty answerable. Anyways, just wanted to drop it here for your more experienced eyes.
 
@thesecretmaster it doesn't seem understandable at all to me, but if you want to advocate for it, fix it up first. Of course when you do we'll probably conclude it's a dupe...
 

« first day (3291 days earlier)      last day (1656 days later) »