I’m using pyomo to find an approach for solving an energy optimization problem. I’m trying to find the optimal time slot during a day to shift the start of a smart dishwasher to, so that the electricity cost is minimized. I’m using an example from a paper but unfortunately I can’t embe…
Pytorch’s nn.TransformerEncoder “src_key_padding_mask” not functioning as expected
Im working with Pytorch’s nn.TransformerEncoder module. I got input samples with (as normal) the shape (batch-size, seq-len, emb-dim). All samples in one batch have been zero-padded to the size of the biggest sample in this batch. Therefore I want the attention of the all zero values to be ignored. The …
integer formatting does not work in Python
I am trying to save my images with the time epoch plus iterating integers like this: text_img.save(‘/content/result/’ + epoch + ‘_%03d’ + ‘.png’ , format=”png”) However, the output is something like this: 16087965_%03d.jpg The formatting does not work for some r…
Detect rectangles in an image with Python
I have a large collection of binary images like these ones: On each image I need to detect the white rectangle. The rectangles have different dimensions and orientations and sometimes they are interrupted by a black line (see image 2). I think the problem is easy to solve if one could remove the noisy backgro…
Amount of months calculation in DataFrame in Python Pandas?
I have DataFrame like below: And I need to calculate number of MONTHS from Date column until today. Below I upload result which I need: Answer You can modify this solution for subtract by scalar d:
Change displot bar colors to a specific color
I am struggling to change my displot bar colours. I want to change the colour of the bars to the light blue colour on at the end of the palette (shown below). I have tried this, but the colour seems to remain as a dark blue, which is not what I want. How do I change the colours to a
Tried several methods but this Value Error keeps popping up running with the WebDriver
Below is the part where my code program meets a runtime ValueError. As I’m using selenium as part of the program, im taking webelements into a variable then convert the variable to a float number as it is on the website. Below is the error: Tried several different methods to solve this ValueError but al…
Drawing a rectangle with Matplotlib
I’m writing a python function to draw a simple rectangle, the vertex points are parameters. Well, this does not work correctly and I can’t seem to find out why its plotting all over the place. EDIT: as for my imports. So sp is sympy. As for the expected result to draw a rectangle of course. Actual…
VSCode on WSL does not have right-click options features, such as find code reference
I am running VSCode on WSL, but unfortunately I lost a lot of functionalities. For example, when I right-click on a function, it only shows: There is no option for example to do code referencing. As comparison, here is the right-click option when I run VSCode on Windows: Any solution? Thanks! Answer You have …
How to reset the index counter?
I’m implementing a game (connect four). A player makes a move by selecting a column number to place their checker in, when the column is empty the checker is placed at row index (-1) if not I’m decrementing the index by -1. I am having trouble resetting the row index so that after both players pla…