I am looking for a way to easily split a python array in half.
So that if I have an array:
A = [0,1,2,3,4,5]
I would be able to get:
B = [0,1,2]
C = [3,4,5]
Let us say that we have following array:
my @arr=('Jan','Feb','Mar','Apr');
my @arr2=@arr[0..2];
How can we do the same thing if we have array reference like below:
my $arr_ref=['Jan','Feb','Mar','Apr'];
my $arr_ref2; # How can we do something similar to @arr[0..2]; using $arr_ref ?
I got asked this question once and still haven't been able to figure it out:
You have an arrayof N integers, where N is large, say, a billion. You want to calculate the median value of this array. Assume you have m+1 machines (m workers, one master) to distribute the job to. How would you go about doing this?
Since the median is a nonlinear operator, you can't just find the median in each machine and then take the median of those values.
Im using the answer to this question to convert an arrayof XML to a single XML output:
http://stackoverflow.com/questions/2554671/output-array-of-xml-to-plain-xml
Im using the simpler solution of the two there (Marked as the answer)
It all works for me, however at the start of the output I get:
string(109960) "
Can anyone shed any light on this? Output here: http://bit.ly/aoA3qY
Is there a way to initialize an arrayof primitives, say a integer array, to 0? Without using a for loop? Looking for concise code that doesn't involve a for loop.
:)
Hi,
I have an arrayof type string that looks like this:
"test1|True,test2|False,test3|False,test4|True".
This is essentially a 2d array like so
[test1][True]
[test2][False]
[test3][False]
[test4][True].
I want to convert this into a dictionary<string,bool> using linq, something like:
Dictionary<string, bool> myResults = results.Split(",".ToCharArray).ToDictionary()
any ideas?
I have a object store in Java. My C program stores data (in form of char array) in java. Now I wish to retrieve data from my store. I cannot find any function call that returns me an char array. How can I do this?
Hi all,
I came cross a question in my interview.
Question:
Arrayof integers will be given as the input and you should find out the middle element when sorted , but without sorting.
For Example.
Input: 1,3,5,4,2
Output: 3
When you sort the given input array, it will be 1,2,3,4,5 where middle element is 3.
You should find this in one pass without sorting.
Any solutions for this?
i want to add the current string in a textview view to a string array in arrays.xml.then display the last/previous string of that array in a textview (setText).
I am using the DataTables plugin for jQuery and need to get one of the table rows. DataTables has a fnGetNodes function that returns an Array with all of the DOMElements of the table. I would like to use a jQuery selector to find that row (I know the id of the row), but I need to convert the Array to a jQuery Object, is this possible?
I want to copy a string into a char array, and not overrun the buffer.
So if I have a char arrayof size 5, then I want to copy a maximum of 5 bytes from a string into it.
what's the code to do that?
Hi ,
I have country table,
i fetch all values and moved into array ,
these value i like to populate into combo/dropdown list ,
here i want to do some magic things,
that is , for my site most of the users coming from uk,us,Australia,Romain and few,
So i like to populate by my preference ,
is there any array will do this magic work, else is it possible mysql query ,
So final question is ,
Populate country name into combo based on my prefernce ,
Thanks
I have an arrayof field names. I would like to use those to populate the keys of another array, which will have empty values as default. Is there a single command I can do this with?
RubyParser.new.parse "1+1"
s(:call, s(:lit, 1), :+, s(:array, s(:lit, 1)))
Above code is from this link
Why there is array after + in the Sexp. I am just trying to learn ruby parser and the whole AST thing. I have been programming for a while but have no formal education in computer science. So do point to good article which explains AST etc. Please no dragon book. I tried couple of times but couldn't understand much of that book
Hi everyone, I'm trying to find an elegant way in Coffeescript to merge an arrayof arrays, so that [[1,2,3],[4,5,6],[7,8,9]] == [1,2,3,4,5,6,7,8,9].
As you might imagine, I need this because I'm generating arrays from a function in a "for in" construct and need to concatenate the resulting nested array:
result = (generate_array(x) for x in arr)
Is there an elegant way to handle this? Thanks for any pointers!
I need to pass two array list references to a function and return the reference of merged array list.
how can i do it????
pls help....
public int merge(ArrayList x, ArrayList y)
{
List all = new ArrayList();
all.addAll(x);
all.addAll(y);
System.out.println(all);
return all;
}
is it correct???
how to search substring from mutable array?
NSMutableArrray names having string values,
searchText is a substring to search from name array values.
for (NSString *sTemp in names)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
//NSLog(@"sTemp = %@, searchText = %@",sTemp,searchText);
NSLog(@"%@",titleResultsRange.length);
if (titleResultsRange.length > 0)
[Items addObject:sTemp];
}
I'm looking for a way to define and send a JSON object array. I've figured out how to define a single JSON object, turn it into a string and send it, but what about an arrayof this type? Probably something simple I'm overlooking...
var myColumnSetting = { "ColumnName": name,
"ColumnIndex": index
}
convert it to a string
var myJSONText = JSON.stringify(myColumnSetting, false);
Hi,
this is my first question on Stackoverflow, please bear with me.
I'm testing an algorithm for 2d bin packing and I've chosen PHP to mock it up as it's my bread-and-butter language nowadays.
As you can see on http://themworks.com/pack_v0.2/oopack.php?ol=1 it works pretty well, but you need to wait around 10-20 seconds for 100 rectangles to pack. For some hard to handle sets it would hit the php's 30s runtime limit.
I did some profiling and it shows that most of the time my script goes through different parts of a small 2d array with 0's and 1's in it. It either checks if certain cell equals to 0/1 or sets it to 0/1. It can do such operations million times and each times it takes few microseconds.
I guess I could use an arrayof booleans in a statically typed language and things would be faster. Or even make an arrayof 1 bit values. I'm thinking of converting the whole thing to some compiled language. Is PHP just not good for it?
If I do need to convert it to let's say C++, how good are the automatic converters? My script is just a lot of for loops with basic arrays and objects manipulations.
Thank you!
Edit. This function gets called more than any other. It reads few properties of a very simple object, and goes through a very small part of a smallish array to check if there's any element not equal to 0.
function fits($bin, $file, $x, $y) {
$flag = true;
$xw = $x + $file->get_width();;
$yh = $y + $file->get_height();
for ($i = $x; $i < $xw; $i++) {
for ($j = $y; $j < $yh; $j++) {
if ($bin[$i][$j] !== 0) {
$flag = false;
break;
}
}
if (!$flag) break;
}
return $flag;
}
I have an array $x with nonzero number of elements. I want to create another array ($y) which is equal to $x. Then I want to make some manipulations with $y without causing any changes to $x. Can I create $y in this way:
$y = $x;
In other words, if I modify $y created in the above shown way, will I change value of $x?
Hi,
I have an arrayof (4) floating point numbers and need to sort the array in descending order. I'm quite new to c++, and was wondering what would be the best way to do this?
Thanks.
How do I show the dates number format next to its name in the array using PHP? So that the number format is saved in the database and the month name is displayed?
Here is the php code.
$month_options = array("Month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");