How to slice an array

hi,

it is probably a trivial question, but I could not find it in the documentation: how do you slice an array in SC?

a = [1,2,4,5,7,8];

Let’s say I want the first three values, or some values in the middle, how can I do that?
In python would be something like:
a[0:3]
a[2:5]
How can do that in SC?

Thanks!

[1, 2, 3, 4, 5][2..3]
[1, 2, 3, 4, 5][2..]
[1, 2, 3, 4, 5][..2]
// etc
2 Likes

that was easy, thank you!

can do non-contiguous too:

[1, 2, 3, 4, 5, 6][[2, 4]]

for fancy multi-dimensional slicing see ‘J Concepts in SC’ in the help

2 Likes