2D array slicing by float value in Python

I want to slice an array of [x,y] coordinate pairs by x value in Python 3.x, in a similar way to the solution to this question but with coordinates rather than a 1d list. For example for the (numpy) array of coordinates I want a function like: coo...
more »

2017-01-16 21:01 (4) Answers

Integer[] can not be converted to Serializable

I am trying to pass Integer[] to a function that accepts <T extends Serializable>. I know Integer implements Serializable. Why can not I pass Integer[]? How to resolve this issue? classPropsUpdater { public static <T extends Serializabl...
more »

2017-01-16 18:01 (0) Answers

How to create a map of key:array in shell?

I want to create map in shell. Where each value is an array. So the map is key:array pair. For example it can be like this : "Key1" : a1 a2 a3 a4 "key2" : b1 b2 b3 "key3" : c1 basically my code looks like this listService(){ serviceType=$1 servi...
more »

2017-01-16 12:01 (2) Answers

create object a random number of times ruby

def pass_growing_season self.age += 1 if self.age >= 6 harvested_oranges << Orange.new #NEED 100 - 300 !!! end if self.height < 25 self.height += 2.5 end end I am trying to initialize an Orange class that is defined in anot...
more »

2017-01-15 21:01 (2) Answers

Type casting char array to char **

If I do this: #include <stdio.h> typedef char **arr2D; char arr1D [5 * 10]; int main (void) { ((arr2D)arr1D)[0][0] = '_'; printf("%c", arr1D[0]); return(0); } I receive crash, which suggests undefined behavior. Why can't I d...
more »

2017-01-15 11:01 (1) Answers

Array and Objects in javascript

If length is passed in square bracket notation of an array. It returns first element. What is the underlying logic here? var foo= []; foo['0'] = 'hello'; foo[2] = {'fun': true}; foo[length]; ...
more »

2017-01-15 10:01 (1) Answers

Summing an Array with random values

I need to make a function that sums my array, which is filled with random values. My function only returns 0 and not an actual summation of the array. I don't have much experience with arrays or random values, how can I code my arrSum function to giv...
more »

2017-01-14 19:01 (2) Answers

Why would C have "fake arrays"?

I'm reading The Unix haters handbook and in chapter 9 there's something I don't really understand: C doesn’t really have arrays either. It has something that looks like an array but is really a pointer to a memory location. I can't really i...
more »

2017-01-14 17:01 (5) Answers

Push method with new Array

I would like to push some element in a 2-D empty Array, and I find some problem with the push method. var a = [[],[],[]]; a[1].push(1); console.log(a); //result: [ [], [ 1 ], [] ] The above code will get the correct result, but the push method al...
more »

2017-01-13 23:01 (3) Answers

C Multiple arrays permutations algorithm

I'm trying to write a program that generates permutations upon a list of words stored into several arrays. For example, my program asks for 2 groups of words like this : words #1: abc def ghi words #2: 123 456 What i'm trying to have is this outp...
more »

2017-01-13 11:01 (1) Answers

Group together array elements

I have an array in PHP:- $arr = ["BX_NAME0","BX_NAME1","BX_NAME2","BX_categoryName0","BX_categoryName1","BX_categoryName2","BHA_categories0","BHA_categories1","BHA_categories2"] Here I want to group together elements based on same ending integer ...
more »

2017-01-13 11:01 (3) Answers

Count Items in an Array of Arrays?

If I have an object that is declared as let compoundArray = [Array<String>] is there a property that would give me the number of strings in all the arrays contained in compoundArray? I can do it by adding up all the items in each array wit...
more »

2017-01-13 10:01 (3) Answers