## Bin elements per row - Vectorized 2D Bincount for NumPy

I have a NumPy array with integer values. Values of matrix range from 0 to max element in matrix(in other words, all numbers from 0 to max data element presented in it). I need to build effective( effective means fast fully-vectorized solution) for s...
more »

2017-09-16 18:09 (1) Answers

## Transform a mesh of quads and triangles into a mesh composed of only triangles

I do not know how to explain my problem well comprehensively. So I'll show you an example ... I have this array indicating the vertices indices for each quad or triangle: >>> faces array([[0, 1, 2, 3], [4, 7, 6, 5], [0, 4, 1,...
more »

2017-09-16 17:09 (2) Answers

## get all indexes of value nil in array

I have an array of N elements and this array contains either 0, 1 or nil. I want to get all indexes at which nil is present or sort the array so that all nil comes first. I am looking for an efficient way because the array size can be very large. H...
more »

2017-09-16 06:09 (1) Answers

## AS3: Inefficient to make too many references across classes?

I was told once that I should avoid referencing properties and such of my main game class from other classes as much as possible because it's an inefficient thing to do. Is this actually true? For a trivial example, in my Character class would MainG...
more »

2017-09-14 21:09 (1) Answers

## Why is specializing a monadic function with Identity less efficient than writing it manually?

I have need two higher-order functions, one taking a side-effect free function and the other taking a monadic function as argument: frobM :: Monad m => (a -> m a) -> b -> m b frob :: (a -> a) -> b -> b They are very similar, t...
more »

2017-09-14 15:09 (0) Answers

## Eigen + MKL or OpenBLAS slower than Numpy/Scipy + OpenBLAS

I'm starting with c++ atm and want to work with matrices and speed up things in general. Worked with Python+Numpy+OpenBLAS before. Thought c++ + Eigen + MKL might be faster or at least not slower. My c++ code: #define EIGEN_USE_MKL_ALL #include <...
more »

2017-09-13 22:09 (2) Answers

## Application behaviour different while fetching data from cache

I have an complete application that takes 7-8 seconds while fetching a particular key value from cache ( Ncache server ). Previously it use to take 1-2 seconds. Now all of a sudden it has changed behaviour( Not sure why and how ). To test, i created ...
more »

2017-09-13 13:09 (0) Answers

## Push reference of string element in an array in to new array of string

Given the following code: var old_Array =["One","Two","..."]; var len = old_Array .length; var new_Array =[]; for(var i=0;i<len;++i) { new_Array.push(old_Array [i]); // ----- [1] } After line [1] new_Array is fille...
more »

2017-09-13 09:09 (2) Answers

## Track the rows which were updated or encrypted

I want to scrub(or encrypt) the email information from a few tables which are older than a few years. This I am planning to do as part of a job, next time when I run the job how can I omit the rows which are already scrubbed or encrypted. I am look...
more »

2017-09-13 09:09 (2) Answers

## Generic extension method is slower than non-generic extension method

I wrote an extension method for Lists that finds the index of a given value (or the next bigger value) in a sorted list. public static int LinearSearch(this List<int> list, int startIndex, int value) { for (int i = startIndex; i < list....
more »

2017-09-12 17:09 (1) Answers

## Java Streams: distinct() on a pre-sorted stream?

As discussed in this question, the implementation of distinct() is able to use a more efficient algorithm when the stream it operates on is known by the runtime to be sorted. How can we achieve a similar result if we know that the stream is sorted (...
more »

2017-09-12 15:09 (1) Answers

## Conversion of number to date affect the performance in oracle

I have below query where the DT_ID is number data type column and the value stored in this column is date in the format 'YYYYMMDD'. In my below query I want to get the previous week data from Monday till Sunday for weekly reporting and this query w...
more »

2017-09-12 15:09 (1) Answers

## Could CDN be faster way to load resources?

I was setting up the admin panel for a blog today, and I decided just to use the CDN bootstrap link rather than keeping the files local on the server since this was just some initial testing. I figured that I would add the files to the server later i...
more »

2017-09-12 02:09 (4) Answers

## HTML - Removing elements takes more time than adding elements - Why?

I have a table with a lot of rows (like 10.000). When I receive new data I want to clear the rows first. Weirdly enough, clearing the table takes much longer than building the rows from scratch. Right now I clear the table with jQuery empty(): \$(#...
more »

2017-09-11 09:09 (1) Answers

## Best way to iterate over an array that uses its own output

Firstly, I'd like to apologize for the badly worded title - I can't currently think of a better way to phrase it. Basically, I'm wondering if there's a faster way to implement an array operation in Python where each operation depends on previous outp...
more »

2017-09-11 05:09 (3) Answers

## How to optimize memory access pattern / cache misses for this array decimate/downsample program?

I was recently asked about a piece of code to decimate/downsample the array "in-place". This "decimation" function takes an array of ints and stores an entry at an even index i in the array at the index i/2. It does it for all entries in the array. ...
more »

2017-09-10 10:09 (5) Answers

## Quickest sorting mechanism for sorting by multiple predicates in python

import operator a = [[1,0.7,1],[4,0.8,1],[5,0.8,0.99],[11,0.9,0.98]] b = sorted(a, key=lambda x:x[1], reverse=True); c = sorted(b, key=lambda x:x[2], reverse=True); s = sorted(a, key=lambda x : (x[2],x[1]), reverse=True); i = sorted(a, key = operator...
more »

2017-09-09 05:09 (1) Answers

## What is the fastest way to compute sum of weighted products between columns?

np.random.seed([3, 14]) df = pd.DataFrame(np.random.randn(5, 3), columns=list('ABC')) df A B C 0 -0.602923 -0.402655 0.302329 1 -0.524349 0.543843 0.013135 2 -0.326498 1.385076 -0.132454 3 -0.407863 1.302895 -0.604236 ...
more »

2017-09-08 10:09 (2) Answers

## Python - slice array at different position on every row

I have a 2D python array that I want to slice in an odd way - I want a constant width slice starting on a different position on every row. I would like to do this in a vectorised way if possible. e.g. I have the array A=np.array([range(5), range(5)...
more »

2017-09-07 10:09 (3) Answers

## Index of the first and last numbers 1 of each column of an 2d array

I have a 2d array (Q) consisting of only zeros and ones (binary matrix). For each column of Q I want to find the index of the first and last row which the value 1 occurs. Each column contains at least one 1. Here's an example: [[1, 1, 1, 0, 0, 0, 0...
more »

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

## How is Underscrore's now method is faster?

I am curious how Underscore's _.now method is faster than just new Date().getTime(). I see the following on their github codebase. // A (possibly faster) way to get the current timestamp as an integer. _.now = Date.now || function() { return new...
more »

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

## Comparing Numpy and Matlab array summation speed

I recently converted a MATLAB script to Python with Numpy, and found that it ran significantly slower. I expected similar performance, so I'm wondering if I'm doing something wrong. As stripped-down example, I manually sum a geometric series: MATL...
more »

2017-09-06 07:09 (2) Answers

## How can I improve performance of this minmax implementation?

Here is my current code. It's a naive implementation. import System.Environment (getArgs) minmax [] = Nothing minmax [x] = Just (x, x) minmax (a:b:xs) = Just \$ minmax' xs \$ sort a b where minmax' [] lohi = lohi minmax' [x] lohi@(lo, h...
more »

2017-09-05 23:09 (1) Answers

## PHP Array or Function - Which is more efficient in this Scenario

Using PHP 5.6, and will be moving to 7.0 within next 12-18 months on this particular application. So we have a quite large global config file -- which holds by now close to 100 variables (and each update gets more). As you would expect, this config ...
more »

2017-09-05 20:09 (1) Answers

## Is a deep object slow in JavaScript? If so how much

Simple question: is there a merit of using a shallow object over a deeper one? When I write a code, I tend to use a deep object just so it is easy to understand and classify. But I am wondering if this custom is making my code slower. I have done a ...
more »

2017-09-05 06:09 (2) Answers

## Performance of various numpy fancy indexing methods, also with numba

Since for my program fast indexing of Numpy arrays is quite necessary and fancy indexing doesn't have a good reputation considering performance, I decided to make a few tests. Especially since Numba is developing quite fast, I tried which methods wor...
more »

2017-09-04 19:09 (1) Answers

## Python performance improvements and coding style

Question Let's assume the following sparse table is given indicating the listing of a security on an index. identifier from thru AAPL 1964-03-31 -- ABT 1999-01-03 2003-12-31 ABT 2005-12-31 -- AEP ...
more »

2017-09-04 17:09 (1) Answers

## Efficient concatenation ignoring suffixes in index

I do have two dataframes like this: import pandas as pd df1 = pd.DataFrame({"c1": range(5), "c2": range(1, 6)}, index=list("ABCDE")) df2 = pd.DataFrame({"c3": range(15, 21), "c4": range(11, 17)}, index=["A_suf1", "B_suf2", "A_suf2", "C_suf2", "B_su...
more »

2017-09-03 19:09 (2) Answers

## Postgres performance degrading as cache gets consumed

I migrated a Postgres database 9.1 doing 300K transactions/hour from a server with Red Hat OS, Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz / 16 Core, 64 GB RAM, 240 GB x 4 Intel SSD TO Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz / 56 Core, 128 GB RAM, 2TB...
more »

2017-09-03 15:09 (0) Answers

## How to reduce code of multiple if statements

I am trying to validate a large contact form. When the user forgets a required input field then I populate the empty variable with default text. My current solution uses nine if statements. Is there a better way to do it with less code? html: &l...
more »

2017-09-03 09:09 (3) Answers

## Would it be efficient to sort with indexes

So I was thinking of a new sorting algorithm that might be efficient but I am not too sure about that. 1) Imagine we have an array a of only positive numbers. 2) We go through the array and find the biggest number n. 3) We create a new array ...
more »

2017-09-02 19:09 (2) Answers

## Fast subsetting of a matrix in R

I face the following problem: I need many subsets of a big matrix. Actually I just need views as input for another function f(), so I don't need to change the values. However it seems, that R is terribly slow for this task, or I'm doing something wr...
more »

2017-09-02 18:09 (2) Answers

## No performance gain with transpose of large 2d Matrix using Loop tiling

Transposing global 2D Square Matrix/Array of size 1 gb with tiling approach(Cache Aware) has no performance gain in single threaded execution over Normal transpose method. Not discussing the transpose speed up using AVX,SSE(SIMD) or any other cache ...
more »

2017-09-02 09:09 (1) Answers

## JavaFX textarea displaying big file

I'm trying to show on screen a textfile content using JavaFX textarea. I success doing it with small files, but with big ones everything becomes too slow. File with size 64KB was read in 1 second, and it takes 2 minutes to display it. There is code: ...
more »

2017-09-01 07:09 (1) Answers

## Long long int makes my Sieve of Eratosthenes super slow?

I have a program that requires me to find primes up till 10**10-1 (10,000,000,000). I wrote a Sieve of Eratosthenes to do this, and it worked very well (and accurately) as high as 10**9 (1,000,000,000). I confirmed its accuracy by having it count the...
more »

2017-08-30 08:08 (1) Answers