## How to sort a batch of 2D tensors in tensorflow?

I have a tensor A with the shape of [#batch, #MaxSequence, #Features], where the actual lengths of the 2nd dimension (may be less than #MaxSequence) are stored in a tensor L. I want to sort A by the 2nd feature in the 3rd dimension on the sequence in...
more »

## Returning the N largest values' indices in a multidimensional array (can find solutions for one dimension but not multi-dimension)

I have a numpy array X, and I'd like to return another array Y whose entries are the indices of the n largest values of X i.e. suppose I have: a =np.array[[1, 3, 5], [4, 5 ,6], [9, 1, 7]] then say, if I want the first 5 "maxs"'s indices-here 9, 7 ...
more »

## PHP: order array with a user-defined comparison function and alphabetically by two values

it's my first post and I hope I do not make any mistakes. I have a choir memberlist as array: \$members = Array ( [0] => Array ( [0] => Bert [1] => T [1] => Array ( [0] => Claudia [1] => S...
more »

## PHP array sorting associative array using a specifc key value

I have an array which need to sort using a key value of "odbyx" Here is the array var_dump array(12) { ["id"]=> array(7) { [0]=> string(1) "8" [1]=> string(1) "7" [2]=> string(1) "3" [3]=> string(1...
more »

## Adding 2 matrices using pointers

I can acheive it by passing (c,a,b) to add_mat function, where result of a,b is stored in c like, void add_mat(int c[][3], int a[][3], int b[][3], int m, int n) What should be the return type of add_mat if I want to construct the funtion in this w...
more »

## Creating a list of many ndarrays (different size) in python

I am new to python. Do we have any similar structure like Matlab's Multidimensional structure arrays in Python 2.7 that handles many ndarrays in a list. For instance, I have 15 of these layers (i.e. layer_X, X=[1,15]) with different size but all are ...
more »

## numpy binned mean, conserving extra axes

It seems I am stuck on the following problem with numpy. I have an array X with shape: X.shape = (nexp, ntime, ndim, npart) I need to compute binned statistics on this array along npart dimension, according to the values in binvals (and some bins), ...
more »

## Inconsistent python print output

(Python 2.7.12) - I have created an NxN array, when I print it I get the exact following output: Sample a: SampleArray=np.random.randint(1,100, size=(5,5)) [[49 72 88 56 41] [30 73 6 43 53] [83 54 65 16 34] [25 17 73 10 46] ...
more »

## Fill a 3D numpy array with ones based on a 2D array with indices

I have 2 numpy arrays output and index: output = np.zeros((3,3,3)) >>>index array([[0,1,2], [1,0,0], [2,2,2]]) index represents the index until which output should be populated with ones in the first dimension. The popul...
more »

## Sort a multidimensional array by date Laravel

I need to sort a multidimensional array by date. The data is serialized in a column called prices that contains few values: prices and date. I unserialized this in my controller and I've got \$hlisting->prices. I think that this prices is an array and...
more »

## How to store multidimensional subscript as variable in R

Suppose I have a matrix, mat <- matrix((1:9)^2, 3, 3) I can slice the matrix like so > mat[2:3, 2] [1] 25 36 How does one store the subscript as a variable? That is, what should my_sub be, such that > mat[my_sub] [1] 25 36 A list g...
more »

## PHP - Group Multi-dimensional Array by Value(a) and sort each Group by Value(b)

I have an array containing fruits and vegetables that are all mixed together. I would like to group each item by their type ie 'vegetable' (indicated by value = 1) or 'fruit'(indicated by value = 2) and then have each item positioned in the order ass...
more »

## Validate PHP multidimensional array (nestable) to avoid infinite loop

I am using https://github.com/dbushell/Nestable library. Everything works fine using the library but I want to validate the request as an extra protection to avoid infinite loop if someone will force the request manually (hypothetical). I was wonde...
more »

## Refactor multidimensional array function to ES6

Currently putting together a function in my app and was wondering if theres a neater way to write this with ES6 rather than use two for loops. The aim is create a multi-dimensional array to track co-ordinates x & y. This works fine as it stands...
more »

## How to fill a 2D Python numpy array with values from a generator?

Based on the answers here it doesn't seem like there's an easy way to fill a 2D numpy array with data from a generator. However, if someone can think of a way to vectorize or otherwise speed up the following function I would appreciate it. The diff...
more »

## How do I group elements of a numpy array by two?

I am facing the following problem. I have an np.array, of the following structure: [A, B, C, D, E, F] where A..F are numpy arrays, guaranteed to be of the same size. I am hoping to achieve the following shape: [ A | B, C | D, E | F ] where A | ...
more »

## VBA: Strings and arrays - splitting 1d arrays into 2d arrays

I've got a String array containing a string of items separated by "." Ex.: 0: Test1.Test2.Test3.Test4.Test5 1: Testa.Testb.Testc.Testd.Teste ... I need to split these strings into a 2D String array with 5 elements per array. Ex.: 0, 0: Test1 0,...
more »

## C Programming - Sum of 2D arrays

I am trying to get the values of diagonal values from a 2D array. For example.. 10 20 30 10 20 30 10 20 30 From my codes, I will be adding/summing the numbers from index[0][0] with index1 and index[2][2] USING POINTERS which will compute to 60. H...
more »

## Get indices and values of an ndarray in NumPy

I have a ndarray A of arbitrary number of dimensions N. I want to create an array B of tuples (array, or lists) where the first N elements in each tuple are the index and the last element is the value of that index in A. For example: A = array([[1...
more »

## 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 »

## The order of axis when printing a NumPy array

I am working with 3d arrays in NumPy, and I have to look at the array elements a lot. Say I have array a where a.shape is (10,5,3). I am using this is the sense of 3 planes of shape (10,5), and I would like to view it as such. For example if I pr...
more »

## 2-dimensional array name 1st element

C Programming in One Hour a Day has this quote: As with a one-dimensional array, the name of a multidimensional array is a pointer to the first array element. #include <stdio.h> int m[2][4]; int main() { printf("%p\n", m); /...
more »

## Creating a multi-dimensional array in PHP with an uncertain depth

Good Evening - I am trying to create a multi-dimensional array based on an exploded text string of a account codes stored in the database. The account codes will be of varying lengths/depths. Say for example \$test in the array below are similar to ...
more »

## Sort a multidimensional array ascending and nominate a subarray to always be first

I have a multidimensional array: \$array = array ( "B" => array ("Banana", "Yello"), "O" => array ("Orange", "Orange"), "A" => array ("Apple", "Green"), "S" => array ("Strawberry", "Red") ); \$o = \$array['O']; // this is the lette...
more »

## How would I sort an Array of Std Class Objects by specific listing order?

I have an array of StdClass Objects and that contains several different Car Types (ex. Compact Car, Minivan, etc.) which is sorted by price. I would like to sort the array in the following order: Economy Car Compact Car Mid-Size Car Standard-Size C...
more »

## 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 »

## Fill blocks at random places on each 2D slice of a 3D array

I have 3D numpy array, for example, like this: array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]], [[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, ...
more »

## Conditional PDO Delete statement probably not working

The portion that is trying to delete duplicate entries in the database seems incorrect. So I suppose I am asking what would be the correct way to do that in this example. I am not totally new to PHP , but this is beyond me. If you could please tell m...
more »

## Dot product between 2D and 3D numpy arrays

I have 2 arrays x and y with shapes (2, 3, 3), respectively, (3, 3). I want to compute the dot product z with shape (2, 3) in the following way: x = np.array([[[a111, a121, a131], [a211, a221, a231], [a311, a321, a331]], [[a112, a122,...
more »

## Sort Multidimensional Array By Searched Word

I need to sort a multidimensional array by a searched keyword. My array is like below. <?php array( array( 'name' => '11th-Physics', 'branch' => 'Plus One', 'college' => 'Plus One', ), array( 'name' => 'JE...
more »

## Array of 3 Dimensions to an Array of Objects

Been stuck on this for a while. let employees = [ [ ['firstName', 'Joe'], ['lastName', 'Blow'], ['age', 42], ['role', 'clerk'] ], [ ['firstName', 'Mary'], ['lastName', 'Jenkins'], ['age', 36], ['role', 'manager'] ] ] To yield: ...
more »

## Most efficient way to apply Look Up Tables to NUMPY array in Python 3

I am trying to squeeze as much performance as I can using numpy arrays. I have a Look Up Table say for e.g. MYLUT = [0,2,5,7,8,12,-1,...,229] And I have an numpy array MYARRAY with uint8 values of shape (300,200000) What is the fastest way to appl...
more »

## How to flatten and sort a multi-dimensional array containing numbers and subarrays of numbers?

I need help sorting a multi-dimensional array consisting of numeric strings and arrays of numeric strings. Here is my code: \$array = array(); \$multi= array( 10, 9, array(5,4), array(6,7), ...
more »

## Initializing and filling multi dimension array in javascript

How do we initialize and create new multi dimension array? Let's imagine if I want to initialize a 4x4 multi dimension array and fill it with 0's Ideally, in 2D arrays, we would do let oned_array = new Array(10).fill(0); // would create array of s...
more »