Dear all,
Would there be an interest for having an "Array.deleteElement(array, index)" entry within the macro language methods? Such deletion could be performed with the code below, but could not be too easy to figure out: function ArrayDeleteElement(array, index) { return Array.concat(Array.slice(array, 0, index - 1), Array.slice(array, index, array.length)); } My best regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
> On Mar 27, 2019, at 7:06 AM, Philippe CARL <[hidden email]> wrote:
> > Dear all, > > Would there be an interest for having an "Array.deleteElement(array, index)" > entry within the macro language methods? Thanks to Norbert Vischer, the ImageJ 1.52o7 daily build adds an Array.delete(array,value) macro function that can be used to delete array elements by value or by index. Here is an example: // delete using a value a1 = Array.getSequence(10); Array.reverse(a1); without3 = Array.delete(a1, 3); // delete using indexes a2 = Array.getSequence(10); a22 = Array.copy(a2); a22[5] = NaN; a22[6] = NaN; without5and6 = Array.delete(a22, NaN); // delete using string value a3= newArray("one", "two", "three", "four"); withoutTwo = Array.delete(a3, "two"); Array.show(a1, without3, a2, without5and6, a3, withoutTwo); -wayne > Such deletion could be performed with the code below, but could not be too > easy to figure out: > > function ArrayDeleteElement(array, index) > > { > > return Array.concat(Array.slice(array, 0, > index - 1), Array.slice(array, index, array.length)); > > } > > My best regards, > > Philippe -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
I'm not a macro language user, but I'm curious: how does Array.delete(a1,3) know that the '3' is an index and not a value?
Please forgive me if this is obvious. (perhaps Arrays cannot hold integer values??) -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. > On Mar 29, 2019, at 11:09, Wayne Rasband <[hidden email]> wrote: > >> On Mar 27, 2019, at 7:06 AM, Philippe CARL <[hidden email]> wrote: >> >> Dear all, >> >> Would there be an interest for having an "Array.deleteElement(array, index)" >> entry within the macro language methods? > > Thanks to Norbert Vischer, the ImageJ 1.52o7 daily build adds an Array.delete(array,value) macro function that can be used to delete array elements by value or by index. > > Here is an example: > > // delete using a value > a1 = Array.getSequence(10); > Array.reverse(a1); > without3 = Array.delete(a1, 3); > > // delete using indexes > a2 = Array.getSequence(10); > a22 = Array.copy(a2); > a22[5] = NaN; > a22[6] = NaN; > without5and6 = Array.delete(a22, NaN); > > // delete using string value > a3= newArray("one", "two", "three", "four"); > withoutTwo = Array.delete(a3, "two"); > > Array.show(a1, without3, a2, without5and6, a3, withoutTwo); > > -wayne > > >> Such deletion could be performed with the code below, but could not be too >> easy to figure out: >> >> function ArrayDeleteElement(array, index) >> >> { >> >> return Array.concat(Array.slice(array, 0, >> index - 1), Array.slice(array, index, array.length)); >> >> } >> >> My best regards, >> >> Philippe > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Good day Kenneth!
"Please forgive me if this is obvious." Wayne's examples show that the mechanism is always value-based- Regards Herbie ::::::::::::::::::::::::::::::::::::::::::: Am 29.03.19 um 17:48 schrieb Kenneth Sloan: > I'm not a macro language user, but I'm curious: how does Array.delete(a1,3) know that the '3' is an index and not a value? > Please forgive me if this is obvious. > > (perhaps Arrays cannot hold integer values??) > > -- > Kenneth Sloan > [hidden email] > Vision is the art of seeing what is invisible to others. > > > > > >> On Mar 29, 2019, at 11:09, Wayne Rasband <[hidden email]> wrote: >> >>> On Mar 27, 2019, at 7:06 AM, Philippe CARL <[hidden email]> wrote: >>> >>> Dear all, >>> >>> Would there be an interest for having an "Array.deleteElement(array, index)" >>> entry within the macro language methods? >> >> Thanks to Norbert Vischer, the ImageJ 1.52o7 daily build adds an Array.delete(array,value) macro function that can be used to delete array elements by value or by index. >> >> Here is an example: >> >> // delete using a value >> a1 = Array.getSequence(10); >> Array.reverse(a1); >> without3 = Array.delete(a1, 3); >> >> // delete using indexes >> a2 = Array.getSequence(10); >> a22 = Array.copy(a2); >> a22[5] = NaN; >> a22[6] = NaN; >> without5and6 = Array.delete(a22, NaN); >> >> // delete using string value >> a3= newArray("one", "two", "three", "four"); >> withoutTwo = Array.delete(a3, "two"); >> >> Array.show(a1, without3, a2, without5and6, a3, withoutTwo); >> >> -wayne >> >> >>> Such deletion could be performed with the code below, but could not be too >>> easy to figure out: >>> >>> function ArrayDeleteElement(array, index) >>> >>> { >>> >>> return Array.concat(Array.slice(array, 0, >>> index - 1), Array.slice(array, index, array.length)); >>> >>> } >>> >>> My best regards, >>> >>> Philippe >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Friday, 29 March 2019 16:56:10 GMT [hidden email] wrote:
> "Please forgive me if this is obvious." > > Wayne's examples show that the mechanism is always value-based- Hm...I am confused too. I think the explanation may not be correct: >> Thanks to Norbert Vischer, the ImageJ 1.52o7 daily build adds an >> Array.delete(array,value) macro function that can be used to delete >> array elements by value or by index. According to the examples it is only "by value" and not "by index"? For example if I want to delete the 5th entry in the array (i.e. "by index"): a1 = newArray(0,2,2,2,4,6,8,8,8,10) w = Array.delete(a1, 5); Array.show(w); 0 2 2 2 4 6 8 8 8 10 - - - The 5th element is "6" but I guess the delete function is looking for value "5", which is absent, so the 5th element does not get deleted. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Good day Gabriel,
did you follow the examples given by Wayne? Best greetings Herbie ::::::::::::::::::::::::::::::::::::::::::::: Am 29.03.19 um 19:25 schrieb Gabriel Landini: > On Friday, 29 March 2019 16:56:10 GMT [hidden email] wrote: >> "Please forgive me if this is obvious." >> >> Wayne's examples show that the mechanism is always value-based- > > Hm...I am confused too. > > I think the explanation may not be correct: > >>> Thanks to Norbert Vischer, the ImageJ 1.52o7 daily build adds an >>> Array.delete(array,value) macro function that can be used to delete >>> array elements by value or by index. > > According to the examples it is only "by value" and not "by index"? > > For example if I want to delete the 5th entry in the array (i.e. "by index"): > a1 = newArray(0,2,2,2,4,6,8,8,8,10) > w = Array.delete(a1, 5); > Array.show(w); > 0 > 2 > 2 > 2 > 4 > 6 > 8 > 8 > 8 > 10 > - - - > The 5th element is "6" but I guess the delete function is looking for value > "5", which is absent, so the 5th element does not get deleted. > > Cheers > > Gabriel > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Friday, 29 March 2019 18:32:14 GMT [hidden email] wrote:
> Good day Gabriel, > > did you follow the examples given by Wayne? Yes, of course, :-) and I also read the explanation of what the command does and I think something is not right: >> Array.delete(array,value) macro function that can be used to delete >> array elements by value or by index. Note the "or by index" at the end of the sentence. Regards Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hmm,
I understand that you need some more lines for "index-delete": // delete using indexes a2 = Array.getSequence(10); a22 = Array.copy(a2); a22[5] = NaN; a22[6] = NaN; without5and6 = Array.delete(a22, NaN); Maybe I'm wrong. Best Herbie ::::::::::::::::::::::::::::::::::::::::::::: Am 29.03.19 um 19:37 schrieb Gabriel Landini: > On Friday, 29 March 2019 18:32:14 GMT [hidden email] wrote: >> Good day Gabriel, >> >> did you follow the examples given by Wayne? > > Yes, of course, :-) and I also read the explanation of what the command does > and I think something is not right: > >>> Array.delete(array,value) macro function that can be used to delete >>> array elements by value or by index. > > Note the "or by index" at the end of the sentence. > > Regards > > Gabriel > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Friday, 29 March 2019 18:40:57 GMT [hidden email] wrote:
> Hmm, > I understand that you need some more lines for "index-delete": > > // delete using indexes > a2 = Array.getSequence(10); > a22 = Array.copy(a2); > a22[5] = NaN; > a22[6] = NaN; > without5and6 = Array.delete(a22, NaN); > > Maybe I'm wrong. Oops, now I see... one sets the desired index to delete to NaN, then delete it. Thanks for the clarification. Regards Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Herbie
And if, for some reason, a22 already contains some NaN values that you do NOT want
to remove? I suspect that "remove by value" is actually implemented, but "remove by index" is problematic. Wayne's example appears to assume that there is a known value (NaN) which cannot possibly occur in the Array. This will work every time, until the middle of an important demo to the funding agency. I would prefer a specific function to remove an element by index. -- Kenneth Sloan [hidden email] Vision is the art of seeing what is invisible to others. > On Mar 29, 2019, at 13:40, Herbie <[hidden email]> wrote: > > Hmm, > > I understand that you need some more lines for "index-delete": > > // delete using indexes > a2 = Array.getSequence(10); > a22 = Array.copy(a2); > a22[5] = NaN; > a22[6] = NaN; > without5and6 = Array.delete(a22, NaN); > > Maybe I'm wrong. > > Best > > Herbie > > ::::::::::::::::::::::::::::::::::::::::::::: > Am 29.03.19 um 19:37 schrieb Gabriel Landini: >> On Friday, 29 March 2019 18:32:14 GMT [hidden email] wrote: >>> Good day Gabriel, >>> >>> did you follow the examples given by Wayne? >> Yes, of course, :-) and I also read the explanation of what the command does >> and I think something is not right: >>>> Array.delete(array,value) macro function that can be used to delete >>>> array elements by value or by index. >> Note the "or by index" at the end of the sentence. >> Regards >> Gabriel >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by CARL Philippe (LBP)
> On Mar 27, 2019, at 7:06 AM, Philippe CARL <[hidden email]> wrote:
> > Dear all, > > Would there be an interest for having an "Array.deleteElement(array, index)" > entry within the macro language methods? Today’s ImageJ daily build (1.52o9) adds the Array.deleteValue(arr,value) and Array.deleteIndex(arr,index) macro functions. The following example macro shows how to use these new functions. -wayne // delete a numeric value a1 = Array.getSequence(7); Without3 = Array.deleteValue(a1, 3); // delete a string value a2 = newArray("one", "two", "three", "four"); WithoutTwo = Array.deleteValue(a2, "two"); // delete using an index a3 = Array.getSequence(5); Array.reverse(a3); WithoutIndex1 = Array.deleteIndex(a3, 1); Array.show(a1, Without3, a2, WithoutTwo, a3, WithoutIndex1); -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks a lot Wayne for these two additions!
Le Samedi 30 Mars 2019 16:19 CET, Wayne Rasband <[hidden email]> a écrit: > > On Mar 27, 2019, at 7:06 AM, Philippe CARL <[hidden email]> wrote: > > > > Dear all, > > > > Would there be an interest for having an "Array.deleteElement(array, index)" > > entry within the macro language methods? > > Today’s ImageJ daily build (1.52o9) adds the Array.deleteValue(arr,value) and Array.deleteIndex(arr,index) macro functions. The following example macro shows how to use these new functions. > > -wayne > > // delete a numeric value > a1 = Array.getSequence(7); > Without3 = Array.deleteValue(a1, 3); > > // delete a string value > a2 = newArray("one", "two", "three", "four"); > WithoutTwo = Array.deleteValue(a2, "two"); > > // delete using an index > a3 = Array.getSequence(5); > Array.reverse(a3); > WithoutIndex1 = Array.deleteIndex(a3, 1); > > Array.show(a1, Without3, a2, WithoutTwo, a3, WithoutIndex1); > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |