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
7
votes
2 answers

Replicating changes in a list

Imagine I have a list of items: - A - B - C Now from somewhere a server tells my application that element B was removed, yet it only provides the entire new list, not the exact change details. Since WinRT ListViews automatically animate…
7
votes
5 answers

Get difference between associative rows of two 2-dimensional arrays

I have two arrays and these arrays contain information about id, linklabel and url in the following format: $pageids = [ ['id' => 1, 'linklabel' => 'Home', 'url' => 'home'], ['id' => 2, 'linklabel' => 'Graphic Design', 'url' =>…
6
votes
3 answers

Behavior of array_diff_uassoc not clear

First of all I need to mention that I digged into manual and php docs and didnt find an answer. Here's a code I use: class chomik { public $state = 'normal'; public $name = 'no name'; public function __construct($name) { …
Karol
  • 7,803
  • 9
  • 49
  • 67
6
votes
1 answer

jq remove element from array by value

I'm using jq and trying to remove an element from an array based on it's value by can't figure out the syntax, it works with map but not del: input = [10,11,12] echo $input | jq -r 'map(select(. == 10))' returns [10] echo $input | jq -r…
twiglet
  • 63
  • 1
  • 3
6
votes
6 answers

Ruby: How to find difference between 2 arrays, order matters

I'm trying to count the differences between two arrays where the order DOES matter. For example: array_one = ["A", "B", "C"] array_two = ["B", "C", "A"] This would yield 3 differences because: array_one[0] != array_two[0] array_one[1] !=…
morrime
  • 463
  • 9
  • 18
5
votes
3 answers

array_diff to compare two associative arrays

I'm confusing array_diff behavior why genre don't exist on diff array? Do you know how to resolve the matter? -code '0', 'value02' => 'v2', 'genre' => '1', 'type' => 'text', 'contry' => 'us', …
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106
5
votes
1 answer

Array difference as a series of actions

In short: I have two arrays which may be different, and I'll like to get the difference/transformation as a series of "actions" (adds and removes). That is, in a basic example: Current: [a, b, d] Desired: [a, b, c, d] Actions: Add c in position…
nickf
  • 537,072
  • 198
  • 649
  • 721
4
votes
1 answer

array_diff not working as expected ? What could be the reason?

I have two arrays . Check the code $array1 = array(0=>'215',1=> '225'); $array2 = array(0=>'225'); $diff_result = array_diff($array1, $array2); $diff = array_values($diff_result); print_r($array1);echo "
"; print_r($array2);echo…
Wazy
  • 8,822
  • 10
  • 53
  • 98
4
votes
5 answers

Do multi-dimensional arrays cause any problems in C and/or C++?

I know that this question seems a little bit hilarious at the first sight. But as I came across this question I´ve found a comment, of @BasileStarynkevitch, a C and C++ high-level user, in which he claimed that multidimensional arrays shall not be…
4
votes
1 answer

Find mapping that translates one list of clusters to another in Python

I am using scikit-learn to cluster some data, and I want to compare the results of different clustering techniques. I am immediately faced with the issue that the labels for the clusters are different for different runs, so even if they are…
4
votes
1 answer

Converting arrray values to integer from request in laravel

I want to array_diff() two arrays in Laravel. The first array looks like this: array:4 [ 0 => 7248 1 => 7249 2 => 7250 3 => 7251 ] the second one: array:4 [ 0 => "7248" 1 => "7249" 2 => "7250" 3 => "7251" ] this one I get with…
Michael Ploeckinger
  • 1,616
  • 1
  • 11
  • 24
4
votes
4 answers

How to get the difference between two arrays?

I have 2 arrays: arr1 = [[11,12],[11,13],[11,14], [12,13]]; arr2 = [[11,13],[11,14]]; Expected result [[11,12],[12,13]]. How can I get the difference between the two arrays? I use lodash _.difference but it gives me a wrong answer.
Truong Cong Hau
  • 151
  • 1
  • 6
4
votes
2 answers

Perl: Removing array items and resizing the array

I’m trying to filter an array of terms using another array in Perl. I have Perl 5.18.2 on OS X, though the behavior is the same if I use 5.010. Here’s my basic setup: #!/usr/bin/perl #use strict; my @terms = ('alpha','beta test','gamma','delta…
Eric A. Meyer
  • 920
  • 6
  • 20
4
votes
5 answers

How to construct a matrix of all possible differences of a vector in numpy

I have a one dimensional array, lets say: import numpy as np inp_vec = np.array([1, 2, 3]) Now, I would like to construct a matrix of the form [[1 - 1, 1 - 2, 1 - 3], [2 - 1, 2 - 2, 2 - 3], [3 - 1, 3 - 2, 3 - 3]]) Of course it can be done with…
user3176500
  • 389
  • 2
  • 6
  • 15
4
votes
5 answers

How to find the differences from 2 ArrayLists of Strings?

I have 2 Strings: A1=[Rettangolo, Quadrilatero, Rombo, Quadrato] A2=[Rettangolo, Rettangolo, Rombo, Quadrato] I want to obtain this: "I have found "Quadrilatero", instead of "Rettangolo" ". If I use removeAll() or retainAll() it doesn't work…
Lorenzo Calosci
  • 55
  • 1
  • 1
  • 5
1
2
3
18 19