Skip to content

Tag: python

Hashing the content of a method in Python

I am looking for a robust way to hash/serialize the content of a method in Python. Use-case: We are doing some file caching the result of a transformation function, and it would be great if it was possible to automatically refresh if transformation function has changed: I am looking for something that could p…

How to draw points of a sphere in a cubic environment?

Given a center point (x0, y0, z0) and a radius (g_radius) I want to use Python to generate points in a sphere in a cubic world (= Minecraft). I’m trying to use this algorithm (I found it here on so) but it’s not precise and I have to increase the number of samples to a ridiculous huge number to ge…

How to sort MultiIndex using values from a given column

I have a DataFrame with 2-level index and column with the numerical values. I want to sort it by level-0 and level-1 index in such a way that the the order of 0-level index is determined by the sum of values from Value column (descending), and the order of 1-level index is also determined by the values in Val…

Select pytorch tensor elements by list of indices

I guess I have a pretty simple problem. Let’s take the following tensor of length 6 Now I would like to to access only the elements at specific indices, lets say at [0, 3, 4]. So I would like to return I found torch.index_select which worked great for a tensor of two dimensions, e.g. dimension (2, 4), b…

Not able to download a file through request in python

When I try to download a file online it doesn’t work for a particular site while it works for others. Why is this happening and what should I do about it? I write the content of the dl request in my case https://drivers.amd.com/drivers/amd-software-adrenalin-edition-22.11.1-win10-win11-nov15.exe (warnin…