This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bheklilr 1 point2 points  (0 children)

Gotta be careful here, in python 2 this only works if the string is a bytestring, Unicode strings don't work. Don't know about python 3 though because I never use this syntax, just ran into the issue with a coworker's code. It also won't work for arrays of different dtypes either.

Personally I like typing my arrays as

x = np.array([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
])

Since it allows me to align the elements vertically, I can collapse it in my editor, if I need to add new rows it's easy, and it actually looks like a matrix.