I’m trying to use regex to find a specific file name in a folder, however it seems like my regex is not working. Inside my folder the names of the excel files are Answer You are not testing your regex against anything. pattern.fullmatch will return a method object. You probably wanted to write That bein…
Orbit integration in galpy without specifying the time steps array
I just discovered galpy and went all day through documentation and examples but I am still a little confused about the possibility to integrate an orbit without specifying the set of times. A simple example present in the documentation reads: but I ask if it’s possible to use the integrate method withou…
How do i get the min and max value of tuples
How do i get the code to return 2 (lowest of all) and 29 (the biggest one) Answer When searching for the min, you want to first take the min of each tuple and then take the min through those. You can achieve this with map which has the advantage of not having to create an extra list in the
How do I implement the datetime module into my code?
So how do I make the string a date? The error: Answer When you’re creating your object you have to enclose the value inside quotes: Just 21.12.1999 by itself isn’t a valid Python definition of anything. You can then use strptime of the datetime.datetime module to parse it into a datetime, and retr…
More pythonic way of creating within-class scatter matrix
I am looking for a better way of calculating the following I would prefer getting rid of the for loops using numpy. This is the within-class scatter matrix for fischers linear discriminant. Answer You can write as follows: This is because sum_i x_i x’_i = X’ X, where X is (N, 3) matrix and x_i = X…
How to convert a PyTorch sparse_coo_tensor into a PyTorch dense tensor?
I create a sparse_coo tensor in PyTorch: Now I want to convert a PyTorch sparse tensor into a PyTorch dense tensor. Which function can be used? Answer you can use to_dense as suggested in this example : And by the way, the documentation is here
Get the number of specific dictionary values being stored in a 2-dimensional list in Python
I have a dictionary that contains fruits as keys and a 2-dimensional list including the line number and the timestamp, in which the fruit name occurs in the transcript file, as values. The 2-dimensional list is needed because the fruits appear several times in the file and I need to consider each single occur…
Sorting the values of a dictionary based on values of other dictionary
I have a dictionary that looks like this.. and I have another dictionary with some score like this.. I want to sort the values of “results” dictionary based on values of “score” dictionary. For example, For the key ‘agunii2035’, the score dictionary has values [ 4,4,1,3]. S…
Scraping #document from an iframe tag using beautifulsoup
I am trying to scrape a website for COVID related data. The data is enclosed in an iframe tag. I tried to scrape the results using beautifulsoup but couldn’t extract #document. Here’s my approach My results: Inspect Data from website: Can somebody explain that why the #document part is missing fro…
‘event’ has no “key” attribute
** this is a part of a code ** ** error shows that: 38, in _cheak_events elif event.key == pygame.KEYDOWN: AttributeError: ‘Event’ object has no attribute ‘key’ Answer Replace all event.key with event.type