Skip to content

create a matrix from combinations with values

I have some combinations like Any idea on how I efficiently can create a four by four matrix with these 0,1 values from all these combinations? So the result will be something like: Answer Imagine if the “combinations” are stored in a file in the following format (or similar): Then you can do: Exa…

Pulling x-values of spline integer y-values?

I have the given sample data and interpolated spline: I would like to pull the x values that correspond to the integer y values of the spline, but am not sure how to do this. I assume I will be using np.where() and have tried (to no avail): Answer You could use the find_roots function from this post to find

Removing Lines from Contourf in Matplotlib

I am using the following code to contour plot some data using contourf in matplotlib. I have set the transparency of the colourbar to 0.6, but there are annoying lines between each colour interval that I cant get rid of. There doesnt seem to be a way to set linestyle in contourf, any ideas? Answer You can add…

Finding first index after symbol

I need to extract emails from random text strings. For example: I found out how can i find end of email: But how can i find it’s start index? Maybe we could reverse string and find first ‘ ‘ after @ but how can we do it? Answer This is a very non-trivial approach without using regular expres…

Python property setter only

I have a class with property decorator. But I don’t need the getter, can I have property with only the setter? It’s most more a curiosity. Answer The simplest way IMHO is Demo:

Import “cv2” could not be resolved

I’ve installed python and opencv by using the correct commands in the cmd, but when I type in ‘import cv2’ in a python then I get the error in visual studio code and I can’t find any solution online how to fix this More of the error in the terminal Answer I noticed that Visual Studio d…