I have a list in Mathematica, and I'm trying to get all the other numbers in the list and save it as a new list.
I currently have
ReadList["file",Number]
which reads the entire list, { x1, x2, x3, x4, ... } ; I just want to select any other number and save it in a new list, for example. { x1, x3, x5, ... } .
{ x1, x2, x3, x4, ... }
{ x1, x3, x5, ... }
How to do it?
Try:
yourlist = {a, b, c, d, e, f, g, h}; (* use Span: search for Span or ;; in Documentation Center *) everyotheritemlist = yourlist[[1 ;; -1 ;; 2]]; (* or use Take *) Take[yourlist, {1, -1, 2}]
Both give:
{a,c,e,g}
For such tasks, there are always dozens of creative ways to do this in Mathematica. kguler has already given you canonical ways, but here's another one:
Partition[yourlist, 2]\[Transpose][[1]] (* ==> {a, c, e, g} *)
By the way: There is a Mathematica Stackexchange website at https://mathematica.stackexchange.com/ . The Mathematica community is moving more and more in this direction, so you can also join us.
Another way:
First /@ ReadList["test.dat", {Number, Number}]
Source: https://habr.com/ru/post/908095/More articles:Add metadata to upload image to S3 using Python - content-typeWhy does Java have so many releases, unlike C #? - javaCSS Asset Compilation Error - cssIs it possible to read and write a file with minor changes without knowing its encoding in C #? - c #How do you get multiple error handlers in PHP? - functionHow to run IBAction method programmatically via a button, etc.? - objective-cHow to lock rear key in android when using Qt - c ++perl, add a character to the ith capture group - regexHow can I access indexedDB synchronously? - javascriptExplain how the generator is used in this JavaScript code with IndexedDB? - javascriptAll Articles