New answers tagged

2

Order your imports Imports should be ordered alphabetically in groups of standard library imports, third-party imports and local project imports: import math from operator import itemgetter import random import matplotlib.pyplot as plt import numpy as np import pandas as pd Make use of comprehensions You can rewrite def convert_class_str_to_class_int(...


3

The initial approach definitely has a number of "bottlenecks" and space for optimizations. Let me present and explain the crucial points: starting with good naming: don't give Python identifiers/functions camelCased names. We'll have find_path, get_successors etc. explored dict accumulates a great number of dictionaries (nodes) indexed by their id ...


3

Community wiki - update as posted by the OP in the question based on review by Graipher and AlexV As Graipher and AlexV mentioned the problem with NumPy version was that the inner loop which updates particle positions (x and y) should be performed independently (not repeated in each timestep). The updated version is as follows, def evolve_numpy(self, dt): ...


6

Most of your code looks pretty good, so I'll be highlighting the lines I have thoughts about. But first, are you using Python 3.x? Because if not, please be aware that core dev support for python 2.x will be dropped at the end of this year. So even though you lack the python 3.x tag, I'll pretend you're using it, since all your code looks python 3.x ...


2

Thanks to the answer of @GZ0, the performance of this code snippet is now around 0.0344s on a GPU and around 0.2511s on a CPU. The implementation of @GZ0's algorithm is attached. Please do not hesitate to suggest any modifications to make the code snippet more pythonic :) import timeit import torch import argparse import numpy as np USE_CUDA = torch.cuda....


3

I think a different approach is needed to achieve a better performance. The current approach recomputes the Jaccard similarity from scratch for each possible threshold value. However, going from one threshold to the next, only a small fraction of prediction values change as well as the intersection and the union. Therefore a lot of unnecessary computation is ...


Top 50 recent answers are included