How to marshal multi-dimensional arrays

By this discription about Blittable and Non-Blittable Types in the link below you could try the System.Double in place of float, because they do not require conversion when they are passed between managed and unmanaged code wich means no more special handling by the interop marshaler with a plus in performance: https://msdn.microsoft.com/en-us/library/75dwhxf7%28v=vs.110%29.aspx I did a … Read more

How do I do a deep copy of a 2d array in Java?

Yes, you should iterate over 2D boolean array in order to deep copy it. Also look at java.util.Arrays#copyOf methods if you are on Java 6. I would suggest the next code for Java 6: public static boolean[][] deepCopy(boolean[][] original) { if (original == null) { return null; } final boolean[][] result = new boolean[original.length][]; for … Read more

Multi-dimensional arrays in Bash

Bash does not support multidimensional arrays, nor hashes, and it seems that you want a hash that values are arrays. This solution is not very beautiful, a solution with an xml file should be better : array=(‘d1=(v1 v2 v3)’ ‘d2=(v1 v2 v3)’) for elt in “${array[@]}”;do eval $elt;done echo “d1 ${#d1[@]} ${d1[@]}” echo “d2 ${#d2[@]} … Read more

Loop over array dimension in plpgsql

Since PostgreSQL 9.1 There is the convenient FOREACH which can loop over slices of arrays. The manual: The target variable must be an array, and it receives successive slices of the array value, where each slice is of the number of dimensions specified by SLICE. DO $do$ DECLARE m text[]; arr text[] := ‘{{key1,val1},{key2,val2}}’; — … Read more

Return a 2d array from a function

This code returns a 2d array. #include <cstdio> // Returns a pointer to a newly created 2d array the array2D has size [height x width] int** create2DArray(unsigned height, unsigned width) { int** array2D = 0; array2D = new int*[height]; for (int h = 0; h < height; h++) { array2D[h] = new int[width]; for (int … Read more

numpy divide row by row sum

Method #1: use None (or np.newaxis) to add an extra dimension so that broadcasting will behave: >>> e array([[ 0., 1.], [ 2., 4.], [ 1., 5.]]) >>> e/e.sum(axis=1)[:,None] array([[ 0. , 1. ], [ 0.33333333, 0.66666667], [ 0.16666667, 0.83333333]]) Method #2: go transpose-happy: >>> (e.T/e.sum(axis=1)).T array([[ 0. , 1. ], [ 0.33333333, 0.66666667], [ … Read more