2
$\begingroup$

I have a table given by

example1=Table[N[x^(x/r), 5],{r, 1, 11},{x, 1, 10}];
example2=Accumulate[example1];
example2

I would like to use example2 to create a new table that uses example2's data, but only shows every nth row of the example2 table - in this case (for example), every 2nd, 3rd or 4th row.

How do I do this?

$\endgroup$
  • $\begingroup$ Don't assign something in TableForm to a variable. TableForm is meant for display only, and it cannot be used for computing (without removing it first). Thus, use example2 = Accumulate[...];, then use example2 // TableForm for display or example2[[;; ;; 3]] to take every third row. Look up these in the docs: Part, Span, TableForm. $\endgroup$ – Szabolcs Aug 26 '18 at 12:30
  • $\begingroup$ OK, so let's lose the TableForm. Point taken. Question now edited. But I'm new enough to all this that, whilst I can see that in principle Span and Part could give me what I want, I'm not entirely sure how to put it into practice... $\endgroup$ – Richard Burke-Ward Aug 26 '18 at 12:39
  • 1
    $\begingroup$ But I showed you the exact code you need in my first comment—[[ is Part and ;; is Span. Here it is again: example2[[;; ;; 3]] to take every third row. $\endgroup$ – Szabolcs Aug 26 '18 at 12:43
1
$\begingroup$
example2[[;;;;2]] 

{{1.0000, 4.0000, 27.000, 256.00, 3125.0, 46656., 8.2354*10^5, 1.6777*10^7, 3.8742*10^8, 1.0000*10^10},
{3.0000, 7.5874, 35.196, 278.35, 3195.5, 46908., 8.2454*10^5, 1.6782*10^7, 3.8744*10^8, 1.0000*10^10},
{5.0000, 10.321, 39.409, 285.38, 3208.0, 46931., 8.2459*10^5, 1.6782*10^7, 3.8744*10^8, 1.0000*10^10},
{7.0000, 12.800, 42.742, 290.11, 3215.0, 46942., 8.2461*10^5, 1.6782*10^7, 3.8744*10^8, 1.0000*10^10},
{9.0000, 15.156, 45.694, 293.96, 3220.2, 46949., 8.2462*10^5, 1.6782*10^7, 3.8744*10^8, 1.0000*10^10}}

Alternatively, you can Drop every other row starting with the second row:

Drop[example2, {2, -1, 2}]

same result

$\endgroup$
  • $\begingroup$ OK, got it now! Much appreciated :-) $\endgroup$ – Richard Burke-Ward Aug 26 '18 at 12:43
  • $\begingroup$ @Richard, my pleasure. $\endgroup$ – kglr Aug 26 '18 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.