Skip to content
Discussion options

You must be logged in to vote

Hi, this is a good place to read about slicing.

https://mathjs.org/docs/expressions/syntax.html#matrices
https://mathjs.org/docs/datatypes/matrices.html#getting-or-replacing-subsets
https://mathjs.org/docs/reference/functions/subset.html

Regarding what you are describing, it's something that currently happens only for scalar results.

a = [[1,2],[3,4]]
a[1, 1]    # 1
a[1, :]    # [[1, 2]]

Some relevant discussions:

July 26 2022 #2344

In July 20 2023 at #2994 it was stated that

Maybe a proposal could be that if the index comes from an array, then the result should match the source regardless if it has singleton dimensions.

A = [1, 2; 3, 4]
A[1, 2]          # shall return number 2
A[[1], 2]…

Replies: 2 comments 2 replies

Comment options

dvd101x
Apr 22, 2025
Collaborator Sponsor

You must be logged in to vote
2 replies
@gwhitney
Comment options

@dvd101x
Comment options

dvd101x Apr 23, 2025
Collaborator Sponsor

Answer selected by herdrick
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants