Computing average of non-zero values

I have lists from whose I what the average of non-zero values. E.G [2,2,0,0,0] -> 2 [1,1,0,1,0] -> 1 [0,0,0,9,0] -> 9 [2,3,0,0,0] -> 2.5 Current I'm doing this: list_ = [1,1,0,1,0] non_zero = [float(v) for v in list_...
more »

2017-01-12 01:01 (3) Answers

Sorting Optimization

I'm currently following an algorithms class and thus decided it would be good practice to implement a few of the sorting algorithms and compare them. I implemented merge sort and quick sort and then compared their run time, along with the std::sort: ...
more »

2017-01-10 23:01 (2) Answers

GHC optimization

The two Haskell functions below seems to differ only by whether the index variable is implicit or explicit but the difference in performance is by two orders of magnitude. This function takes about 0.03 seconds to calculate mfib 30: let mfib = (map...
more »

2017-01-09 12:01 (2) Answers

.htaccess configuration for an Image Uploader

So I'm setting up some security and caching in my htaccess for my Laravel Image Uploader and I was wondering if anyone with a bit more knowledge regarding htaccess could inform me if the current setup that I have would be sufficient for the website I...
more »

2017-01-06 03:01 (0) Answers

Python function performance

I have 130 lines of code in which part except from line 79 to 89 work fine like compiles in ~0.16 seconds however after adding function which is 10 lines(between 79-89) it works in 70-75 seconds. In that function the data file( is 100000 line...
more »

2017-01-02 04:01 (2) Answers

Is if else faster than if + default?

I conducted a simple experiment, to compare if-else to only an if (with default values preset). Example: void test0(char c, int *x) { *x = 0; if (c == 99) { *x = 15; } } void test1(char c, int *x) { if (c == 99) { *x...
more »

2016-12-28 10:12 (1) Answers

Optimization of numpy array traversal

1. Consider the following traversal of a numpy.ndarray for ii in xrange(0,(nxTes-2)): if ( (xCom-dtaCri-xcTes[ii]) * (xCom-dtaCri-xcTes[ii+1]) ) <= 0.0: nxL=ii if ( (xCom+dtaCri-xcTes[ii]) * (xCom+dtaCri-xcTes[ii+1]) ) <= 0.0: ...
more »

2016-12-21 21:12 (1) Answers

Is there a faster way to add two 2-d numpy array

Let say I have two large 2-d numpy array of same dimensions (say 2000x2000). I want to sum them element wise. I was wondering if there is a faster way than np.add() Edit: I am adding a similar example of what I am using now. Is there a way to speed ...
more »

2016-12-18 06:12 (1) Answers

Drag formulas without "dragging"

I have few formulas in a row and I want to drag them down. Formulas are complex and I don't have them in R1C1 format and I don't want to convert them into R1C1, but I would like to do something like: Range(A2:B10).Formula = Range.(A1:B1).Formula I ...
more »

2016-11-28 13:11 (3) Answers

Profiling a Single Function Predictably

I need a better way of profiling numerical code. Assume that I'm using GCC in Cygwin on 64 bit x86 and that I'm not going to purchase a commercial tool. The situation is this. I have a single function running in one thread. There are no code depe...
more »

2016-11-24 17:11 (2) Answers