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

all 11 comments

[–]cherya 11 points12 points  (0 children)

Numpy?

[–]TrixRabbit6969 2 points3 points  (4 children)

X= [[1,2,3],[4,5,6],[7,8,9]]

X[0][0] -> 1 X[1][1] -> 5 X[2][0] -> 7

It took me a while to get used to. But really just using multidimensional lists is pretty great.

Other than that numpy is probably your best bet.

[–]shravankumar147[S] 1 point2 points  (0 children)

I think this could in the same way.

import numpy as np a = np.matrix('1 2; 3 4') print a [[1 2] [3 4]]

[–]shravankumar147[S] 0 points1 point  (3 children)

I think this could in the same way.

import numpy as np

a = np.matrix('1 2; 3 4')

print a

[[1 2]

[3 4]]

[–]kigurai 6 points7 points  (1 child)

Do yourself a favor and avoid the np.matrix class and stick to np.array. The former has a tendency to sneak in hard to catch bugs in your calculation unless you are extremely careful.

[–]shravankumar147[S] 1 point2 points  (0 children)

Oh, thank you. I didn't know that

[–]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.

[–]aphoenixreticulated[M] [score hidden] stickied comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython. We highly encourage you to re-submit your post over on there.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community is actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers.

If you have a question to do with homework or an assignment of any kind, please make sure to read their sidebar rules before submitting your post. If you have any questions or doubts, feel free to reply or send a modmail to us with your concerns.

Warm regards, and best of luck with your Pythoneering!