« first day (2143 days earlier)      last day (1078 days later) » 

12:11 PM
@AndrasDeak I'm having a NumPy problem. I have a list with either True or False. Now np.where() can give me a tuple (I think) of indices where the True values are. Now the problem: I have a second list and in that list I want to remove all entries on the indices found using np.where(). However, Python keeps complaining I can't index using tuples, lists, elephants or whatever. I can only use integers (which would mean looping, and that can't be the only solution), or slices.
[np.where()][0] apparently is not a slice
 
no, there are no slices there
convert all your lists to arrays if you want fancy indexing
 
npasarray(np.where())?
 
what?
actually this is an XY problem I think
The Y is second_arr = np.asarray(second_list); second_arr[np.where(first_list)]. The X is mask = np.asarray(first_list); second_arr = np.asarray(second_list); second_arr[mask].
 
    doesClearHelper = []  # Initialise clearance list
    for virus in self.getViruses():  # For all virusses present
        doesClearHelper.append(virus.doesClear())  # Determine clearance
That's what I have thus far. doesClearHelper contains True if the virus in self.getViruses() should go, and False otherwise
 
clear_mask = np.array([virus.doesClear() for virus in self.getViruses()])
Did you write the original code? Camelcase is a crime.
 
12:18 PM
No, MIT
Well, I wrote the doesClearHelper, rest is MIT
@AndrasDeak thanks. And now how to remove the True elements from the list? doing self.virusus[!clear_mask] gives a nice syntax error
 
that's not python :P
 
self.virusus[~clear_mask]
 
which looks like matlab
but otherwise the more verbose np.logical_not
 
~ is binary not which is abused by numpy for elementwise logical not
 
12:27 PM
because I assume like in most languages, a bool is just a uint8 with ignored bits
 
no
I mean yes, but no
In [33]: ~0
Out[33]: -1

In [34]: ~1
Out[34]: -2
you have to make it a boolean not on purpose
In [35]: ~np.arange(2, dtype='uint8')
Out[35]: array([255, 254], dtype=uint8)
 
yeah yeah, just mean that it makes sense as language design to abuse it for logical not on a bool
 
Well, not really. But python's native logical not doesn't work for that's all you can do.
it's still a hack
 
man, I am doing 1 year of python now. And can't get rid of TypeError: 'list' object is not callable because I keep freaking puting parenthesis around everything
@AndrasDeak ah I see I see
 
doing python for 1 year doesn't matter if you keep doing MATLAB :)
I got used to square brackets in weeks
if you have to keep switching it's harder to do both
 
12:30 PM
I still mostly use them, but sometimes my brain shortcircuits
@AndrasDeak yeah, which I do
 
plus your brain is nerfed to begin with :D
 
hahahaha
so true
 
Ander's brain juggling three languages: "why u do dis"
 
for i in range(length(array)):
     int* aux[5];
     aux(:)=np.linspace(1,5)
end
2
 
12:37 PM
virus = SimpleVirus(1.0, 1.0)
patient = Patient([virus], 100)
Updating the patient for 100 trials...
Traceback (most recent call last):
  File "submission.py", line 143, in update
    self.virusus[~clear_mask]  # Remove false virusus
TypeError: ufunc 'invert' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
@AndrasDeak the grader from edx.org hands me this error. Does that mean I can't do self.virusus[~clear_mask]?
 
That says you can't even do ~clear_mask.
Which is silly, of course. What is type(clear_mask), clear_mask.dtype?
At worst you can negate during construction, np.array([not virus.doesClear() for virus in self.getViruses()]). Assuming this method returns bools, which I'm starting to doubt.
I bet it's dtype=object...
I wonder what numpy version that site is running
lol, I think virus.doesClear() returns doubles
that's inexcusable
 
Note: If you want to use numpy arrays, you should add the following lines at the beginning of your code for the grader:
import os
os.environ["OPENBLAS_NUM_THREADS"] = "1"
Then, do import numpy as np and use np.METHOD_NAME in your code.
def doesClear(self):
        """ Stochastically determines whether this virus particle is cleared from the
        patient's body at a time step.
        returns: True with probability self.getClearProb and otherwise returns
        False.
        """

        return random.random() <= self.getClearProb()
That's my doesClear
That should (I think) return a boolean. clearProb is a float between 0 and 1, random.random() is as well
 
yes, that should return a bool
Then I don't understand the error. But you didn't answer my question.
 
I'll test the type
<class 'numpy.ndarray'>
bool
first is for type(clear_mask), second is for dtype
This is the error I get when I try to call this class myself:
Traceback (most recent call last):

  File "<ipython-input-65-aaa6bf7b4dd1>", line 1, in <module>
    P1.update()

  File "D:\MyDocs\PythonedX\ProblemSet3\ps3b.py", line 160, in update
    self.viruses[~clear_mask]  # Remove false virusus

TypeError: only integer scalar arrays can be converted to a scalar index
So I can't use logicals to index?
 
what is the type of self.viruses?
 
12:52 PM
A list of class-instances
 
you can use logical indexes to index a np.array, but not other things I think
 
Urf, this isn't getting any easier
 
@Adriaan that's silly
 
@AndrasDeak I agree :P
 
actually, no
> TypeError: only integer scalar arrays can be converted to a scalar index
that's a different error
"scalar index"???
 
12:54 PM
its because its a list, tho. A list can not be indexed with logical np.array, right?
 
no
@AnderBiguri lists don't know about "scalar arrays"
actually, no, you might be right, sorry!
In [54]: [][np.arange(3)]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-54-3e65612664ea> in <module>
----> 1 [][np.arange(3)]

TypeError: only integer scalar arrays can be converted to a scalar index
I see what's going on
putting an array in a native numpy sequence will call arr.__index__ which raises this error
So yeah, self.viruses is also a list, just like the rest of the code which doesn't use numpy
 
Yes, but it needs to be a list according to the task specifications I've received.
 
so either filter it with python, or convert to an array temporarily
 
You mean either use a loop (somehow?) or do np.asarray(self.viruses) and then index?
 
# filter with python
self.viruses[:] = [virus for virus, clear in zip(self.viruses, clear_mask) if not clear]

# temporary array
self.viruses[:] = np.array(self.viruses)[~clear_mask]
yes
honestly you can just skip clear_mask
 
12:58 PM
so, that second one, are you filling a list with an asigment to an np.array?
 
self.viruses[:] = [virus for virus in self.viruses if not virus.doesClear()]
@AnderBiguri yes, any iterable should work
 
ah well, the more you knwo
 
In [55]: lst = []
    ...: lst[:] = map(float, range(10))

In [56]: lst
Out[56]: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
If you don't have to preserve the original list object you can also omit the [:] in my snippets
 
So, it works on my Spyder, but not on the grader due to this ufunc invert error
 
Just use my last snippet, skip numpy
It's wasteful to convert back and forth
And spyder has a tendency to silently modify your code...
 
1:03 PM
VSC for president
 
Test results
CORRECTSee full outputSee full output
It took a few hours of yelling and a lot of Andras, but I made it!
@AndrasDeak btb, I'm reading this series now, in which the main character has to battle a cult of demonists. The demon, one of the most dangerous in the underworld, is called Andras :P
 
@Adriaan congrats!
@Adriaan beware that one :P
@AnderBiguri ew
 
Yes! the correct reaction to anywhing vim :D
Adriaan, you closed that worng
 
1:38 PM
OP deleted the questions once it got an answer: stackoverflow.com/questions/67519811/…
can we undelete?
I mean, its a shitty question with a shitty answer, but I hate this attitude
 
1:56 PM
needs one more undelvote and an upvote on the answer
 
can OP delete it again if it has been undeleted by the community?
 
@AnderBiguri undeleted
And I upvoted your shitty answer to prevent deleting again.
 
@AnderBiguri yes
Please don’t delete your question after you get help. Instead, accept the answer if it was helpful, and upside it once you have enough rep. — Cris Luengo 3 mins ago
the famous upside privilege ;)
 
@AnderBiguri the first and third column are rounded though. Either they wanted the display mode, as per my dupe, or the question has a shit example dataset
I'd say it's a display issue and they want longG
 
@AndrasDeak I blame my phone. It also autocorrects “its” to “it’s”, which makes me look like an idiot.
 
2:11 PM
nice
It's an iphone, isn't it?
 
2:40 PM
@CrisLuengo thanks mate!
@Adriaan I udnerstood that that is what they wanted, not what they have
but maybe I am wrong, q is shitty
 
2:57 PM
@AndrasDeak Yes. It's an iPhone with an overzealous autocorrect. I do make a lot of typing errors on that little screen with my fat fingers. Without autocorrect nobody would be able to understand what I write.
 
heh
 
 
3 hours later…
5:41 PM
@AnderBiguri some nice mathrock for you open.spotify.com/track/… this whole album is really good :)
 
 
2 hours later…
7:28 PM
oh and cant forget @flawr as well :D
 
8:12 PM
sounds quite mathy:)
 
8:51 PM
:D
 
9:12 PM
posted on May 13, 2021 by Steve Eddins

Recently, I was talking with MathWorks writer Jessica Bernier about the reference page for the imresize function. Jessica pointed out that we don't have an example that shows how to use your own... read more >>

 
 
2 hours later…
11:22 PM
@Feeds "Adaptive Osculatory Rational Interpolation"??? What does that even mean? But damn, the result looks really nice!
How can a non-smooth interpolant do so well?
 

« first day (2143 days earlier)      last day (1078 days later) »