arrays

Convert a python numpy array to c++ stl vector

Hi folks, I'm looking for a way to read in c++ a text file containing numpy arrays and put the data into vector< vector< ... > > , can anyone help me out please ? Thanks a lot. Archy EDIT: format of the text file [[[ 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]] ...

Limited IList<> implementation ?

Hello people, I'm doing some work with stats, and want to refactor the following method : public static blah(float[] array) { //Do something over array, sum it for example. } However, instead of using float[] I'd like to be using some kind of indexed enumerable (to use dynamic loading from disk for very large arrays for example)....

How is Object[] cloneable

Object[] o = new Object[]{}; System.out.println(o instanceof Cloneable); This gives true as o/p. I could not understand why? ...

sort array of size n

if an array of size n has only 3 values 0 ,1 and 2 (repeated any number of times) what is the best way to sort them. best indicates complexity. consider space and time complexity both ...

Deleting a specific item by using array_splice/array_slice in PHP

How do I delete a specific item by using array_splice/array_slice in PHP? for example: array('a','b','c'); how to just delete 'b'? so the array remains: array('a','c'); Thanks ...

Parse error: syntax error, unexpected T_DOUBLE_ARROW PHP

I'm getting a Parse error: syntax error, unexpected T_DOUBLE_ARROW PHP on line 47, which is 'post_content' => $thisShow['content'], Anyone got any ideas why? protected function _saveShow($thisShow) { $saveData = array( 'mid' => $this->_saveAsUserId, 'post_title' => $thisShow['title'], ...

php array in url from json

Here is what I want to do: I have some json like this var foo = { format:"json", type:"test", id:"26443" }; and I awant to put that in a url like this 'http://example.com/a:3:{s:6:"format";s:4:"json";s:4:"type";s:4:"test";s:2:"id";s:5:"26443";}' which I will then put into ajax call but everything I have tried results...

in java, which is better - three arrays of booleans or 1 array of bytes?

I know the question sounds silly, but consider this: I have an array of ints (1..N) and a labelling algorithm. at any point the item the int represents is in one of three states. The current version holds these states in a byte array, where 0, 1 and 2 represent the three states. alternatively, I could have three arrays of boolean - one f...

ArrayList and Map problem in grails

Hi, I have a service that contains a map: static Map cargosMap = ['1':'item1','2':'item 2','3':'item 3'] that is returned via a method in the service: static Map getCargos() { [cargosMap] } A controller calls it like this: def mform = { Map cargos = empService.getCargos() [cargos:cargos] } In the gsp, I have the ...

array read by one element

I have bytes file. Now need to read it by one bytes. How i can make that? Its possible read array and remove readed element? ...

Replace empty cells with logical 0's before cell2mat in MATLAB

I've got a cell array of empty cells and ones that I want to convert to a logical array, where the empty cells are zeros. When I use cell2mat, the empty cells are ignored, and I end up with a matrix of solely 1's, with no reference to the previous index they held. Is there a way to perform this operation without using loops? Example cod...

C# assign char and char array to string?

char character = 'c'; string str = null; str = character.ToString();//this is ok char[] arrayChar = { 'a', 'b', 'c', 'd' }; string str2 = null; str2 = string.Copy(arrayChar.ToString());//this is not ok str2 = arrayChar.ToString();//this is not ok. I'm trying to converting char ar...

Determine if a PHP array uses keys or indices

How do I find out if a PHP array was built like this: array('First', 'Second', 'Third'); Or like this: array('first' => 'First', 'second' => 'Second', 'third' => 'Third'); ??? ...

Calculate sum of objects for each unique object property in Ruby

I was helping with an answer in this question and it sparked a question of my own. Pie is an object that has a pieces array made of of PiePiece objects. Each PiePiece has a flavor attribute How do I create a hash that looks like this: # flavor => number of pieces { :cherry => 3 :apple => 1 :strawberry => 2 } This works, but ...

Is there a more efficient AS3 way to compare 2 arrays for adds, removes & updates?

Hi all - I'm wondering if there is a better way to approach this than my current solution... I have a list of items, I then retrieve another list of items. I need to compare the two lists and come up with a list of items that are existing (for update), a list that are not existing in the new list (for removal) and a list of items that a...

Return a pointer to a char array in C

I've seen a lot of questions on that on StackOverflow, but reading the answers did not clear that up for me, probably because I'm a total newbie in C programming. Here's the code: #include <stdio.h> char* squeeze(char s[], char c); main() { printf("%s", squeeze("hello", 'o')); } char* squeeze(char s[], char c) { int i, j; for(...

How to get the required value displayed from the given array?

From below array i want the value of "_sql" to be displayed or we can I want to echo the "_sql" value, so what should be the syntax to display it in PHP code? JTableMenu Object ( [lft] => [rgt] => [home] => [_tbl] => #__menu [_tbl_key] => id [_db] => JDatabaseMySQL Object ( [name] => mysql ...

Null Pointer Exception on a 2D array (Java)

I have a class, "Tetris", in which one of the instance variables is "board". "board" is 2D array of Color objects. Upon the creation of a tetris object I call a method that sets the dimensions of board and then sets all of the Color objects to be the Default value, that is to say, Color.blue. public Tetris(int rows, int cols) { this.r...

Print array variables when using or not using double quotes.

Hi, When I learning to print array variables, I found the white space inserted when double quoter used. Snippet code as below. Could you please tell me why? #!/usr/bin/perl -w use strict; use warnings; my @str_array = ("Perl","array","tutorial"); my @int_array = (5,7,9,10); print @str_array; print "\n"; # added the double quotes print...

How to sort an array by some specific key?

I have an array look like below. $array[0]['keyword'] = 'cricket '; $array[0]['noofhits'] = '26'; $array[1]['keyword'] = 'food '; $array[1]['noofhits'] = '17'; $array[2]['keyword'] = 'mypax'; $array[2]['noofhits'] = '22'; $array[3]['keyword'] = 'next'; $array[3]['noofhits'] = '22'; $array[4]['keyword'] = 'nextbutton'; $array[4...