Skip to content
Advertisement

Tag: performance

NumPy array row differences

I have a NumPy array vectors = np.random.randn(rows, cols). I want to find differences between its rows according to some other array diffs which is sparse and “2-hot”: containing a 1 in its column corresponding to the first row of vectors and a -1 corresponding to the second row. Perhaps an example shall make it clearer: then I can compute

Lower execution time for apache log parser in Python

I have an school assignment where I were tasked with writing a apache log parser in Python. This parser will extract all the IP addresses and all the HTTP Methods using Regex and store these in a nested dictionary. The code can be seen below: This code works (it gives me the expected data for the log files we were

Getting City from IP Address range

I have an IP address. For example, 192.168.2.10 Also I have a dictionary: Question: How should I find the city from my IP address and use this dictionary spending less time (time complexity) as possible? Answer The “proper answer” if you want the best complexity for arbitrarily large data sets is the one given given by Ji Bin. To really

Efficiently search a long list of lists

I have a long list of hexahedral point coordinates, for example: Each row defines a hexahedron cell, and by iterating over each cell, I extract the defining faces of the cell (6 faces), and add each face to a list processed_faces All of this is fine, but because some cells are sharing the same face, I needed a way to

Generating Scatter Plot from a Matrix

I have a code that generates random matrices of 0’s and 1’s, and I’d like to convert these matrices into scatter plots, where the coordinate corresponds to the matrix row/column, and the color of the scatter point corresponds to the value (red if 0, blue if 1 for example). I’ve been able to do this with matplotlib, but my use-case

Advertisement