« first day (3704 days earlier)      last day (1227 days later) » 

12:13 AM
How come all the arrays inside this list point to the same array

adj = [[]] * nodescount

BUT

When I do it this way the arrays are independant of each other

adj = [[] for _ in range(numCourses)]
 
Because that's how list multiplication works? Of course [[]] * nodescount gives you the same list multiple times; why would it create a copy?
 
maybe I misunderstood it based on examples like this which creates an array of
length 10 each slot filled with zero

[0]*10
I thought it would just fill the list with empty lists...and each list would be a new one (i.e. not pointing to the same one)
 
You'll find that all zeros in that list are the same zero, just like with the list
 
oh i see
but when you use the list comprehension it creates new ones?
 
TL;DR: List multiplication repeats the same element(s); list comprehensions create independent elements because each iteration re-executes the code
 
12:21 AM
ok thank you :)
 
12:59 AM
hello, quick question - how can i only return true if two columns evaluate to false on pandas? thank you!
i used truth_cond = df.col1 & df.col2 to look for columns that both evaluate to true, but doing !truth_cond returns true even when there is only one column that is false (but i want it to only return false when both are false). any pointers, thanks!
 
I don't know pandas, but with the power of a 20-second google search I've arrived at the conclusion that ~(df.col1 | df.col2) should do it
 
Yup
or ~df.col1 & ~df.col2 by the power of Grayskull de Morgan
 
thank you!
 
 
9 hours later…
9:42 AM
cbg
 
cbg
 
cbg
 
I wonder if Python 3.10 is the same as Python 3.1 :-)
 
9:58 AM
Always Start Your Day With A Powerful Early Morning Prayer:
 
Yeah, my bashrc pipes this to cowsay
 
lol
 
 
2 hours later…
11:41 AM
oops. i pressed enter accidentally
guys. I can't seem to use datetime module anymore. it worked last year, the exact same code run like this
f = open("rekaman_aktifitas.txt","a")
now = datetime.now()
date = now.strftime("%m/%d/%Y, %H:%M:%S")
f.write(date+"[aktifitas user]=> "+input+"\n")
f.close()
but now it tells me that ``AttributeError: 'builtin_function_or_method' object has no attribute 'strftime'```
 
you didn't show us your broken import
 
from datetime import datetime
 
>>> from datetime import datetime
... now = datetime.now()
... now.strftime
<built-in method strftime of datetime.datetime object at 0x7fd63d3927b0>
We'll need a proper MCVE. Or you need to restart your jupyter kernel or whatever
 
cbg all, is there an operator equivalent for the ~ operator?
what I mean is and has operator.and_
~ and not are the same then?
 
@python_learner operator.invert
 
11:51 AM
@python_learner they are as same as & and and
@python_learner so I just said something dumb :P
sorry
 
laurel, I will use both and see what gives what I want, thanks
 
@python_learner what I wrote does indeed correspond to not as you asked. I just derped
but you can look at the operator docs and see for yourself
and look at the Data Model to see what dunders implement these
 
yeah will check
 
@AndrasDeak thankyou. turns out "input" variable is causing the problem.
 
"operator.__invert__(obj)Return the bitwise ... ... .. equivalent to ~obj." I was searching for "complement" in the doc page and hence couldn't find this
 
11:56 AM
just search for "~" ¯\_(ツ)_/¯
 
I feel dumb, laurel
 
 
3 hours later…
3:01 PM
@python_learner and is not operator.and_
there is no operation and in the operator module
@python_learner basically you need to read the operator module documentation really carefully
 
3:13 PM
I realize where I went wrong with that
 
 
2 hours later…
4:51 PM
Streaming Advent of Code day 6: twitch.tv/davidism
 
5:36 PM
How do you install Anaconda (not miniconda) on Google Colab?
I did this:
```python
!pip install anaconda
!conda env create --file environment.yml
```
But then it did this:
```bash
Collecting anaconda
Downloading https://files.pythonhosted.org/packages/bd/81/44690deb604d72ffa59ec6e5552f4ef21afb59c8e2698717c8a6be4af09c/anaconda-0.0.1.1.tar.gz
Building wheels for collected packages: anaconda
Building wheel for anaconda (setup.py) ... done
Created wheel for anaconda: filename=anaconda-0.0.1.1-cp36-none-any.whl size=1124 sha256=f7bd16fd00c86bd43929695c19302a9c59fbc2a9570d57fb958aafd4dd33791a
I added !export PATH=~/anaconda3/bin:$PATH before the conda command and it's still not found
Furthermore, how do I check which anaconda (I don't want mini, I need the other) I have from pip?
 
5:58 PM
why would you want anaconda on colab? isn't most of the libraries preinstalled on a colab env?
 
Because I need for this notebook to use the env file with it
Here's the file in question
 
just directly install the dependencies
 
Can those all be installed with pip?
Because if they need to be installed with conda then I'm back where I started
Nevermind, I found a fix
Now the file is "missing"
It's in the drive as the same dir as the ipynb but it's not recognized
How do I get Google Drive path's?
 
6:16 PM
you mount in colab then right click and copy path
 
ok I opened colab (and an old notebook) after a long time and it is automatically mounted now
I remember it asking to copy paste a key to mount, guess its changed
from google.colab import drive
drive.mount('/content/drive')
this should give you a sidebar with your drive folders where you can right click on the file or folder to copy path
 
Alright, new problem: SpecNotFound: Can't process without a name
Not new problem, same problem
That's the same problem, and why I needed to mount the drive
 
@JohnnyApplesauce you asked for this and I thought you wanted that, if its a different issue then its not something I am aware of, sorry
 
6:42 PM
@python_learner congratulations. I'm glad your hard work has paid off :) What area have you gone into, if you don't mind me asking?
 
How in Google Drive do you get the path of a given file?
 
Non-programattically?
 
It's just a UUID at the end of the URL. Otherwise, you're asking about the API?
 
https://pasteboard.co/JDHQ94g.png
It's a
It's from the URL?
What I need is to access that folder. What comes before My Drive/Colab-Notebooks?
 
6:47 PM
I think it's in the URL (recent discussions suggest it might be a UUID of the specific revision). Going back a few years, you could just get a shareable link to a file by right-clicking
 
Because it's apparently not /content/drive and not /content/drive/Colab-Notebooks
 
I think I'm trying to answer this out of context, so I best back off at this point
 
I need to access vocab.txt that you see in the above image from within the
 
The docs definitely do have a UUID but maybe it's not the appropriate way to work on Colab
 
notebook
 
6:49 PM
So what do you see if you right-click that file?
 
1jRgdBHNrzqMJakgVhWlghxVhc8XHWbmC there's your UUID
 
How do I use that in code?
If I try open('1jRgdBHNrzqMJakgVhWlghxVhc8XHWbmC', 'r') can I read it?
 
No. You need the Google developer API. I don't know for Colab, specifically. Maybe they have a shorter route
Although, I guess it could also be a hash of the file. But I think it's a UUID
It's in the docs. Have you gone through that? It seems pretty specific to your particular use-case
 
I tried the same thing `MODEL_SAVE_PATH = '/content/drive/My Drive/Colab-Notebook/bert2gpt'
MODEL_TEMP_PATH = '/content/drive/My Drive/Colab-Notebook/temp'` used in the docs as per the example `with open('/content/drive/My Drive/foo.txt', 'w') as f:`, *after* mounting
 
7:13 PM
Stab in the dark. The suggestion from python_learner was drive.mount('/content/drive') so it should be a relative path from there
In other words, with open('/My Drive/foo.txt', 'w') as f: but I'm guessing
 
Silly me!
I left the s off of Notebooks
Thanks
 
7:28 PM
Alright, with the above out of the way
One cell of the notebook consists of this:
!pip install datasets==1.0.2
!pip install transformers
The next cell terminates execution after the first line:
from datasets import Dataset
With this error:
ModuleNotFoundError: No module named 'datasets'
This is of course after the pip installs say "requirement already satisfied." What could be the problem?
 
Used the wrong pip?
 
You mean pip3 instead? Also no effect
 
7:49 PM
python3 -mpip install ...
or even better
import sys
!{sys.executable} -mpip install datasets==1.0.2
 
Does that work if there are spaces in sys.executable?
 
I think you just saved me AH
 
8:05 PM
Next problem:
Later cells have
!pip install rouge_score, next cell has
from datasets import load_metric
rouge = load_metric("rouge")...
but then this happens:
ImportError: To be able to use this metric, you need to install the following dependencies['rouge_score'] using 'pip install rouge_score' for instance'
 
Typo --> wrong pip --> "next problem". Are you sure we should be the first port-of-call here with your issues?
 
Typo? No typo
I tried AH's trick again, and it worked.
Nvm
 
58 mins ago, by JohnnyApplesauce
I left the s off of Notebooks
 
Ah, but not in the last two cases
 
Sure, hence there being 3 points in my flow diagram
That's not to say that the latest issue isn't valid, but the error explicitly states a potential way to correct it. You never mention whether you even tried it, just presented it as "next problem"
 
8:23 PM
And it's the exact same problem as the one before
 
Bruh, the thing the error says to do is literally above it, which is why I asked, I am literally a doge
 
evening cbg
 
cbg
or should I say khl
 
krt might be applicable
Made some very tasty red cabbage a few days ago. Can recommend.
 
8:36 PM
As a main course or side dish?
 
You saved the water for litmus tests, right? I have a distinct memory of bringing in red cabbage water to primary school to watch it change colour :) (otherwise, I like my red cabbage pickled)
 
@roganjosh that never worked for me
 
@AndrasDeak highlight of our science class. I think we had to concentrate it down a bit, but the assignment was to boil up a cabbage and bring the juice into class the next day
 
we also didn't really have practical assignments
and no "science" class :P
 
Heh, might explain it :)
 
8:40 PM
@AndrasDeak Side dish alongside sautéed chicken and spätzle.
@roganjosh I'd be more than willing to just make another pot as required!
 
@MisterMiyagi I'll allow it
made chicken paprikás today, but I was too lazy for spätzle so just cooked fusilli
 
@MisterMiyagi My sister turned 3 last week and I've been round celebrating (given that she had 2 guests.... her family). She's been watching YT vids about bones and got quite engrossed in what they were talking about (even if she didn't really understand). Given that they have a shed, I now have a perfect excuse to build my Ruben's Tube and not feel washed-up :P
 
I can't connect bones with standing waves
 
Just that she's curious, so I can be a kid and make the things I wanted to make, under the guise that it's for her
 
@AndrasDeak I'll allow it
 
8:46 PM
When really, I just wanted the awesomest equializer
 
I guess you could also start dragging corpses into the shed. She is your excuse.
 
Sure. That's totally the theme I was going for
 
How fast do those flesh eating bugs beetles work? Might be fun to watch :D
 
@roganjosh No idea how A leads to Z, but it sounds awesome ^^
 
@MisterMiyagi I just need a cover story, and she's not just obsessed with Peppa Pig and the interwebs. Give it a few years and I'll have my perfect sound system :P
As long as her curiosity holds for a few more years, that is
 
8:54 PM
I wouldn't expect it to go away :)
 
I hope not! :) My grandfather was nuts in indulging my questions. In a few years, it'd be awesome if I can say "let's go illustrate it" and run off to the shed to make some contraption that I've only learned about in later life
 
9:31 PM
there are some really dope electrostatic experiments so perhaps you should prepare by building a van de Graaff generator
 
 
2 hours later…
11:28 PM
So I was looking through typing.cast in Python 3.6 and noticed that cast actually doesn't do anything in the python source.

def cast(typ, val):
    """Cast a value to a type.

    This returns the value unchanged.  To the type checker this
    signals that the return value has the designated type, but at
    runtime we intentionally don't check anything (we want this
    to be as fast as possible).
    """
    return val
Would make sense to do something like def cast(typ, val) -> typ:
 
You mean def cast(typ: Type[T], val: Any) -> T:?
 
Hmm, does that signature make sense?
linguistically I'd expect cast(from, to), but perhaps it mimics C-style type casts
 
the function doesn't care what you're casting from
 
I mean, I just copied the code from the library ;-)
 
@Aran-Fey I meant the order of params
 
11:37 PM
oh yeah, I agree it would be more intuitive if they were swapped
 
But, ultimately, typing.cast in its present from does absolute nothing, right?
At least def cast(typ: Type[T], val: Any) -> T: actually casts...
 
It does nothing at runtime, but most definitely does something during type checking
 
Wait, but how does it check during type checking?
 
The type checkers special case it
 
heh, not hacky at all
 
11:39 PM
🙏
 
I mean, what other solution is there?
 
I mean there is a perfectly good way to check without the hack?
Like what you wrote...
 
Then they still have to special case it because otherwise the type checker will complain that your Any magically turned into a T
 
Any is the special case?
Or just remove the Any
 
No, the special case is that typing.cast can change the type of a value to whatever you want
 
11:42 PM
Well it can't actually do that at runtime. Its more an additional place to specify the type information. Especially when writing a library where the value is supplied by a caller - This means you don't have control over of the type.
So its more like a static assert for the type checker, than a type cast (which doesn't really exist in python).
 
"static assert for the type checker" is exactly python typing
 
But right now its not, unless the type check has some evil magic to bless that function.
 
I'm not really sure if there's a difference between a type cast and a "hey, type checker, this value is of type T now" assertion
 
There is a difference. The thing is we could do more if the casting function wasn't garbage. For example, libraries like typeguard could handle it correct. So then runtime checking would work, because you could compare iff it was actually castable.
 
I don't understand. Which part of type casting are you unhappy with? What would you like to be different?
 
11:48 PM
I want this signature: def cast(typ: Type[T], val: Any) -> T: so that runtime checking could occur within the cast function. (maybe remove Any)
 
Type checking at runtime can be veeery expensive. In some cases even impossible. (You can't type check the values yielded by a generator, for instance. At least not without making the generator useless)
 
Type checking at runtime exists right now with the typeguard library. I'm going through a large code base and fixing stuff. Certainly not how you run the library in production :-)
Although honestly, doing type checking at every invocation of the cast function shouldn't be too expensive, especially since everybody using the cast function already subscribed to adding extra call overhead...
 

« first day (3704 days earlier)      last day (1227 days later) »