[Scilab-users] Remove duplicate rows and sustain original order of rows

classic Classic list List threaded Threaded
5 messages Options
Iza Iza
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Remove duplicate rows and sustain original order of rows

Hi all,

I can't figure out how to remove duplicate rows from the matrix and go
back to the original order of rows. Function "unique" with an option "r"
sorts rows in lexicographic ascending order.

Thanks in advance for any help,
Iza
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
David Chèze David Chèze
Reply | Threaded
Open this post in threaded view
|

Re: Remove duplicate rows and sustain original order of rows

Hi Iza,

Just consider this tip from the unique help page:

Extracted components, rows or columns can be resorted in their initial order by sorting k:
[N, k] = unique(M);      k = gsort(k,"g",i); N = N(k)
[N, k] = unique(M, "c"); k = gsort(k,"g",i); N = N(:, k)
[N, k] = unique(M, "r"); k = gsort(k,"g",i); N = N(k, :)

Hope it helps,

David


-----Message d'origine-----
De : users <[hidden email]> De la part de Izabela Wójcik-Grzaba
Envoyé : mercredi 13 juin 2018 13:44
À : [hidden email]
Objet : [Scilab-users] Remove duplicate rows and sustain original order of rows

Hi all,

I can't figure out how to remove duplicate rows from the matrix and go back to the original order of rows. Function "unique" with an option "r"
sorts rows in lexicographic ascending order.

Thanks in advance for any help,
Iza
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Remove duplicate rows and sustain original order of rows

Le 13/06/2018 à 14:00, CHEZE David 227480 a écrit :

> Hi Iza,
>
> Just consider this tip from the unique help page:
>
> Extracted components, rows or columns can be resorted in their initial order by sorting k:
> [N, k] = unique(M);      k = gsort(k,"g",i); N = N(k)
> [N, k] = unique(M, "c"); k = gsort(k,"g",i); N = N(:, k)
> [N, k] = unique(M, "r"); k = gsort(k,"g",i); N = N(k, :)
>
> Hope it helps,
No, it does not help, since unique seems to be broken again:

http://bugzilla.scilab.org/show_bug.cgi?id=15610

S.

> David
>
>
> -----Message d'origine-----
> De : users <[hidden email]> De la part de Izabela Wójcik-Grzaba
> Envoyé : mercredi 13 juin 2018 13:44
> À : [hidden email]
> Objet : [Scilab-users] Remove duplicate rows and sustain original order of rows
>
> Hi all,
>
> I can't figure out how to remove duplicate rows from the matrix and go back to the original order of rows. Function "unique" with an option "r"
> sorts rows in lexicographic ascending order.
>
> Thanks in advance for any help,
> Iza
> _______________________________________________
> users mailing list
> [hidden email]
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [hidden email]
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users


--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Remove duplicate rows and sustain original order of rows

In reply to this post by David Chèze
Hello,

----- Mail original -----
De: "CHEZE David 227480"
À: "Users mailing list for Scilab" <[hidden email]>

>Hi Iza,
>
>Just consider this tip from the unique help page:
>
>Extracted components, rows or columns can be resorted in their initial order by sorting k:
>[N, k] = unique(M);      k = gsort(k,"g",i); N = N(k)
>[N, k] = unique(M, "c"); k = gsort(k,"g",i); N = N(:, k)
>[N, k] = unique(M, "r"); k = gsort(k,"g",i); N = N(k, :)

I recently added this tip (in 6.0.1 doc), but it is wrong.
This mistake is already fixed for SCilab 6.0.2 @
https://codereview.scilab.org/#/c/19944/3/scilab/modules/elementary_functions/help/en_US/setoperations/unique.xml

Example:
M = int8([2  0  2  2  1  1  1  2  1  1  0  1  1  0  1  1
          0  1  2  0  1  2  2  0  1  1  2  0  1  0  0  0
          ])
[uc, kc] = unique(M, "c")

// Get unduplicated columns in initial order:
M(:, gsort(kc,"g","i"))

Samuel
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Iza Iza
Reply | Threaded
Open this post in threaded view
|

Re: Remove duplicate rows and sustain original order of rows

Thanks a lot all of you. The first method is fine provided that you
change the last command for: N=M(k,:). I think it is the same as Samuel
wrote in a shorter form.

Iza



W dniu 13.06.2018 15:07, [hidden email] napisał(a):

> Hello,
>
> ----- Mail original -----
> De: "CHEZE David 227480"
> À: "Users mailing list for Scilab" <[hidden email]>
>
>> Hi Iza,
>>
>> Just consider this tip from the unique help page:
>>
>> Extracted components, rows or columns can be resorted in their initial
>> order by sorting k:
>> [N, k] = unique(M);      k = gsort(k,"g",i); N = N(k)
>> [N, k] = unique(M, "c"); k = gsort(k,"g",i); N = N(:, k)
>> [N, k] = unique(M, "r"); k = gsort(k,"g",i); N = N(k, :)
>
> I recently added this tip (in 6.0.1 doc), but it is wrong.
> This mistake is already fixed for SCilab 6.0.2 @
> https://codereview.scilab.org/#/c/19944/3/scilab/modules/elementary_functions/help/en_US/setoperations/unique.xml
>
> Example:
> M = int8([2  0  2  2  1  1  1  2  1  1  0  1  1  0  1  1
>           0  1  2  0  1  2  2  0  1  1  2  0  1  0  0  0
>           ])
> [uc, kc] = unique(M, "c")
>
> // Get unduplicated columns in initial order:
> M(:, gsort(kc,"g","i"))
>
> Samuel
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users