java Arrays.sort 2d array

Use Overloaded Arrays#Sort(T[] a, Comparator c) which takes Comparator as the second argument. double[][] array= { {1, 5}, {13, 1.55}, {12, 100.6}, {12.1, .85} }; java.util.Arrays.sort(array, new java.util.Comparator<double[]>() { public int compare(double[] a, double[] b) { return Double.compare(a[0], b[0]); } }); JAVA-8: Instead of that big comparator, we can use lambda function as following- Arrays.sort(array, … Read more

Split a large dataframe into a list of data frames based on common value in column

You can just as easily access each element in the list using e.g. path[[1]]. You can’t put a set of matrices into an atomic vector and access each element. A matrix is an atomic vector with dimension attributes. I would use the list structure returned by split, it’s what it was designed for. Each list … Read more

data type not understood

Try: mmatrix = np.zeros((nrows, ncols)) Since the shape parameter has to be an int or sequence of ints http://docs.scipy.org/doc/numpy/reference/generated/numpy.zeros.html Otherwise you are passing ncols to np.zeros as the dtype.

Counting the number of non-NaN elements in a numpy ndarray in Python

np.count_nonzero(~np.isnan(data)) ~ inverts the boolean matrix returned from np.isnan. np.count_nonzero counts values that is not 0\false. .sum should give the same result. But maybe more clearly to use count_nonzero Testing speed: In [23]: data = np.random.random((10000,10000)) In [24]: data[[np.random.random_integers(0,10000, 100)],:][:, [np.random.random_integers(0,99, 100)]] = np.nan In [25]: %timeit data.size – np.count_nonzero(np.isnan(data)) 1 loops, best of 3: … Read more