Skip to content

Tag: python

Nested List of Lists to Single List of tuples

I’m trying to turn a nested list of lists (number of lists can be 2 lists +) into a single list of tuples. The list looks something like this: And I would like for it to be like this: I know that if you do zip(list1, list2), it becomes a list of tuple. But how do I go about doing

Replacing Header with Top Row

I currently have a dataframe that looks like this: I’m looking for a way to delete the header row and make the first row the new header row, so the new dataframe would look like this: I’ve tried stuff along the lines of if ‘Unnamed’ in df.columns: then make the dataframe without the he…

sklearn: how to get coefficients of polynomial features

I know it is possible to obtain the polynomial features as numbers by using: polynomial_features.transform(X). According to the manual, for a degree of two the features are: [1, a, b, a^2, ab, b^2]. But how do I obtain a description of the features for higher orders ? .get_params() does not show any list of f…

Extracting coordinates from meshgrid data

I have a cubic grid as shown in the picture below. I would like to list the vertices of each sub-cube, so I would end up with a nested list of sub-cubes with their corresponding list of vertices. My initial attempt was to use a generator, This does give me the desired shape but coordinates are ordered in a ma…

HackerRank Staircase Python

I am trying to solve a problem in HackerRank and I am having an issue with my submission. My code works in PyCharm but HackerRank is not accepting my submission. Here is the problem I am trying to solve: https://www.hackerrank.com/challenges/staircase Here is my code: Any ideas why HackerRank is not accpeting…

numpy second derivative of a ndimensional array

I have a set of simulation data where I would like to find the lowest slope in n dimensions. The spacing of the data is constant along each dimension, but not all the same (I could change that for the sake of simplicity). I can live with some numerical inaccuracy, especially towards the edges. I would heavily…

readkey command in python

I want my Python program to stop and wait until any key is pressed, then to print the key that was just pressed. It’s like the Pascal’s command key := readkey; writeln(key);. I’ ve tried yet to use the msvcrt module and the getch command but it didn’ t work. I tried this: And it didn&#…