# How can parts of a list of lists be printed to the nb, at regular interval positions?

I have a large list of lists with the dimensions {441,21,21,3} of which I need to print the x,y,z data from every 21st part up to 441. How can I print the 21x21x3 piece of every 21st part of this list? Here's what I've tried below that did not do the job. Also is there an more memory efficient way to perform this task?:

Table[Print["mylist parts", mylist[[i++21]]], {i, 1, 441}];

-
Are you sure i++21 is what you meant to write? – Szabolcs May 5 '12 at 12:10

You can select every 21st element using

mylist[[21;; ;; 21]]


You can print them using

Do[Print[mylist[[i]]], {i, 21, 441, 21}]


Regarding memory, having these displayed in the Front End will take more memory than just having the data in kernel memory, so Print /@ mylist[[21;; ;; 21]] may be better. Why do you want to print them? If you're aim is to write to a file, there are other ways.

EDIT

To number the parts, you can use Do[Print[Style[i/21, Large]; Print[mylist[[i]]], {i, 21, 441, 21}]

-
Just for a check at present to make sure I'm getting all the right pieces. I agree this is a memory strain and may not be possible all at one time. Thanks for your help! – R Hall May 5 '12 at 12:16
This works very well! Is there a way to number the parts as their printed? Thanks so much! – R Hall May 5 '12 at 12:21
@RHall Does my edit to the answer help? – Szabolcs May 5 '12 at 12:43
Perfect! Thanks! – R Hall May 5 '12 at 13:30

An alternative is Take

For example:

mat = Array[Subscript[a, ##] &, {50, 3}];

Take[mat, {1, -1, 5}]

-

Here is another way you can select every 21st element of your list.

sel= Table[mylist[[i]],{i,1,Length@mylist,21}];


Because Mathmatica is interactive, you can then examine one, many or all the selected elements that are held in sel by using expressions like:

sel[[1]]        (* first element *)

sel[[7;;11]]    (* elements 7 through 11 *)

sel[[{2,6,14}]] (* elements 2,6,14 *)

sel[[10;;-2]]   (* every element from 10 until the second last element *)


This should let you examine what you have selected whenever you wish without having to use Print;

-
Fantastic! Thanks very much! – R Hall May 5 '12 at 13:31