Close
Close window
Slice - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.
Maplesoft logo
Maplesoft logo

Online Help

All Products Maple MapleSim


[フレーム] [フレーム]

ListTools

Slice

slice a 1-D container into a sequence of sub-containers with the number of elements in each sub-container differing by at most one

Calling Sequence

Slice( Container, numslices, slicesreturned )

Parameters

Container

-

container (list, set, or 1-D rtable), to be sliced into sub-containers

numslices

-

positive integer, specifying the target number of sub-containers

slicesreturned

-

(optional) positive or negative integer, or list/set of positive or negative integers, specifying which sub-containers are to be returned. The default is [seq(1..numslices)].

Description

The command slices a container into a sequence of sub-containers with the number of elements in each sub-container differing by at most one.

If not all the sub-containers are of the same length, the longer containers appear first.

Elements in the returned sequence of sub-containers appear in the same order as the original container.

If the specified number of sub-containers is greater than the number of elements in the original container, then the container is sliced into sub-containers of single elements, followed by empty sub-containers.

When the optional parameter slicesreturned is passed, only the specified sub-containers are computed and returned. Note that an error will be thrown if 0, or any number larger than numslices or smaller than -numslices, is passed.

If a 1-D rtable is to be passed, it can have any integer as initial index, but the initial indices of the returned rtables will all be 1.

Examples

>

withListTools:

Example 1

>

Slice,1

(1)
>

Slice,2

,

(2)

Example 2

>

La,b,c,d,e

La,b,c,d,e

(3)
>

SliceL,1

a,b,c,d,e

(4)
>

SliceL,2

a,b,c,d,e

(5)
>

SliceL,3

a,b,c,d,e

(6)
>

SliceL,4

a,b,c,d,e

(7)
>

SliceL,5

a,b,c,d,e

(8)
>

SliceL,6

a,b,c,d,e,

(9)
>

SliceL,3,1,3

a,b,e

(10)
>

SliceL,3,2

c,d

(11)

Example 3

>

Sa,b,c,d

Sa,b,c,d

(12)
>

SliceS,3

a,b,c,d

(13)

Example 4

>

Vseq1..12

V1234567891012 element Vector[column]

(14)
>

SliceV,3

1234,5678,9101112

(15)
>

SliceV,4,1,1

123,101112

(16)

Compatibility

The ListTools[Slice] command was introduced in Maple 2020.

For more information on Maple 2020 changes, see Updates in Maple 2020 .

The ListTools[Slice] command was updated in Maple 2021.

The Container parameter was updated in Maple 2021.

The slicesreturned option was introduced in Maple 2021.

For more information on Maple 2021 changes, see Updates in Maple 2021 .


Download Help Document

AltStyle によって変換されたページ (->オリジナル) /