Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Show single column array as permutedims of single row #31019

Closed
wants to merge 1 commit into from

Conversation

simonbyrne
Copy link
Contributor

@simonbyrne simonbyrne commented Feb 9, 2019

The current matrix syntax has no elegant way for representing a matrix of a single column. Currently show (and repr) print elements separated by semicolons, which is actually parsed as a vector, e.g.

julia> x = [i for i=1:3, j=1:1]
3×1 Array{Int64,2}:
 1
 2
 3

julia> repr(x)
"[1; 2; 3]"

julia> eval(Meta.parse(repr(x)))
3-element Array{Int64,1}:
 1
 2
 3

This changes it so that it is represented as permutedims of a single row matrix:

julia> repr(x)
"permutedims([1 2 3])"

It's not the most elegant solution: feedback appreciated.

@simonbyrne simonbyrne added the display and printing Aesthetics and correctness of printed representations of objects. label Feb 9, 2019
@simonbyrne
Copy link
Contributor Author

Some other options:

  • define a method Matrix(x::Vector), and print it as Matrix([1,2,3])
  • define a function mat (analogous to vec), and print it as mat([1,2,3]).

@martinholters
Copy link
Member

...or print as hcat([1,2,3]).

@simonbyrne
Copy link
Contributor Author

hcat does look like the simplest option here.

@simonbyrne simonbyrne force-pushed the sb/single-column-matrix branch from 1b88b18 to c02927b Compare April 11, 2019 17:57
@oxinabox
Copy link
Contributor

Re the suggestion of mat, I like that one
I made (and abandonned) a PR for that a while ago
#23790

@simonbyrne
Copy link
Contributor Author

Fixed by #33697

@simonbyrne simonbyrne closed this Feb 13, 2023
@simonbyrne simonbyrne deleted the sb/single-column-matrix branch February 13, 2023 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants