Questions tagged [array-difference]

Used for questions concerning the difference between arrays. For example, where elements in two arrays differ from each other, or subtracting the content of one array from another. Since the tag can be broadly applied to any programming language that supports arrays, use use one or more additional tags in order to help identify the specific language the question relates.

An array is a data structure that encompasses a group of elements. When working with arrays there can be a requirement to determine the difference between two or more arrays, and this tag is for questions relating specifically to finding that difference.

The difference between arrays can be determined in a number of ways, including finding where elements within the array differ, and can include operations such as subtracting the contents of one array from another to produce an outcome.

273 questions
2
votes
3 answers

How to properly confront values from array and echo the result?

I have a script with 10 sets of numeric values. Every set has six different numeric values from 1 to 99.
Francesco
  • 95
  • 6
2
votes
2 answers

Determining the indicies where 2 numpy arrays differ

I've got 2 long numpy arrays, both having 508 elements. I would like to get the indices of where they differ. Most of the solutions I've seen determining difference here sort the arrays which is not suitable in my case. Example arr_1 = [0, 1, 4, 0,…
Alex K
  • 129
  • 6
2
votes
0 answers

How to efficiently generate a percentage difference series from conditionally selected values?

I'm working on a particular problem which I managed to solve in a very inefficient way and I would like to see if there a more efficient way to do it. I have a Dataframe that has its first column filled with positive values and then almost 69…
Gus
  • 193
  • 9
2
votes
5 answers

How to find difference between two same array in JS?

I want to find difference between two arrays. I tried below code from one of the solution given on SF community, but not working from me. My below code is not working if there is number repeated EVEN NUMBER of time(like "7" repeated twice in both…
2
votes
3 answers

Multiple pairwise differences based on column name patterns

I have a data.table, dt: dt Id v1 v2 v3 x1 x2 x3 1 7 1 3 5 6 8 2 1 3 5 6 8 5 3 3 5 6 8 5 1 v1, v2, v3 and x1, x2, x3 are numeric variables I want to subtract the 'x' columns from the 'v' columns, i.e. calculate the…
Kirsten
  • 143
  • 4
2
votes
1 answer

Difference between 2 arrays using perl array_diff utility

I am trying to run array_diff on 2 arrays. sub array_diff(\@\@) { my %e = map { $_ => undef } @{$_[1]}; return @{[ ( grep { (exists $e{$_}) ? ( delete $e{$_} ) : ( 1 ) } @{ $_[0] } ), keys %e ] }; } my $col = 'col'; my…
Rancho
  • 309
  • 4
  • 12
2
votes
3 answers

required difference keys from 2 array in php

I have following 2 arrays, 1) Array ( [109] => 0 [112] => 10 [113] => 0 [110] => 0 ) 2) Array ( [112] => 10.00 ) now i want output as Array ( [109] => 0 [113] => 0 …
Pradeep Sanku
  • 201
  • 1
  • 2
  • 13
2
votes
2 answers

Identifying differences between groups in pandas dataframe

I have a pandas dataframe indexed by date and and ID. I would like to: Identify the ID of additions and deletions between dates Add the ID to another dataframe with the date of the addition/deletion.   date ID value 12/31/2010 13 …
akr24
  • 67
  • 3
2
votes
3 answers

How to find the difference between two arrays in C?

I've been trying to write c programs for finding the union, intersection and difference between two arrays, and while the first two worked out fine, I'm having some trouble finding the difference between two arrays. With difference I mean each…
Doe J
  • 145
  • 1
  • 1
  • 13
2
votes
1 answer

How to diff default array in Laravel?

I've simple array: $array = array(1,5,7,9,3,0); And collection from database: $collection = DB::table('numbers')->pluck('number'); Collection {#194 ▼ #items: array:12 [▼ 0 => "1" 1 => "2" 2 => "3" 3 => "4" …
Andreas Hunter
  • 4,504
  • 11
  • 65
  • 125
2
votes
3 answers

PHP remove array items from another if exists

I have 2 object arrays: Array A and Array B. how can I check if object from Array B exists in Array A. and if exists remove it from Array A. Example: Array A: [ {"id": 1, "name": "item1"}, {"id": 2, "name": "item2"}, {"id":…
blahblah
  • 1,010
  • 15
  • 40
2
votes
2 answers

array_diff() function not showing correct result

array_diff() function not showing correct result:- First Array:- Array( [designation_id] => 1 [name] => Y [fathers_name] => Z [mothers_name] => F [spouse_name] => d [gender] => F [last_achieved_degree] => 2 …
Feroz
  • 143
  • 8
2
votes
1 answer

How to use Reflection to insert data with mysqli by bind_param method? what is difference of these two arrays?

As bind_param($types, $var1, $var2, $var3,..) method of mysqli_stmt class it gets just a series of $variables after second parameter (I want to pass array there), and the number of $variables is unknown in my case, I want to use Reflection in my…
juma
  • 31
  • 5
2
votes
2 answers

Using array_diff() on arrays who holds several objects

I have two arrays. The first array holds these values. [a] => stdClass Object ( [name] => Chris [id] => AaKk4j0abEkJSSxYKKnss2LTZc9BmMDrYmm1TFxkIHR8PSU50OagCsl2pgJjVTm7MrkVBVcJgydJGViRU4HHClyWVm3arL4Y5cdWKyZQHtdltg ) [b]…
Sppidy
  • 403
  • 2
  • 5
  • 15
2
votes
2 answers

How to use array_diff to get the missing item

I'm having trouble using array_diff correctly. I've got 2 arrays: $arr_1 = array( 0 => array('name' => 'Day Rate 2', 'from' => 1200, 'to' => 1400), 1 => array('name' => 'Day Rate 2', 'from' => 2000, 'to' => 2000), ); $arr_2 =…
a53-416
  • 3,585
  • 6
  • 34
  • 44