help with matricies - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: help with matricies (/thread-26513.html) |
help with matricies - ptnb - May-04-2020 Before anyone crucify me for asking a stupid question, I have to point out that I started learning Python 2 weeks ago (and I don't have much time per day, so progress is a bit slow...) Having some experience mainly with C++ (some other languages as well) it was mainly learning language syntax and it was, and still is, easy. But, I believe I am missing something when it comes to matrices, so I figured I should ask here. Now, I know I can use NymPy, but I want to understand how Python basics operate. Let’s say I want to declare 3x3 matrix. To my surprise it was a bit more complicated than simply writing MatrixA[a][b][c]… So, I learned that in Python you have to declare array that will be a member of another array and so on.. But, here is my question: Let say I want to change Matrix[i][j][k]=AnyValue This doesn’t work. Simple (and probably stupid solution) would be to change initial array first – make changes on the k-place. Then put that array in the second one (2x2 matrix) on the “j” place and so on… But, I am sure I’m missing something here. It can’t be that complicated. So, how do I address particular member of the array and how do I change it? Sorry, for a long post… RE: help with matricies - buran - May-04-2020 first of all as per the docs, it's not recommended to use matrix , which may be removed. use array (ndarray)So check Array creation and Array creation routines some examples import numpy as np shape = (3, 3) # define a shape as tuple # Random values m = np.empty(shape) print(m, type(m)) # 1s m = np.ones(shape) print(m, type(m)) # 0s m = np.zeros((3, 3)) # you can pass shape tuple directly print(m, type(m)) # convert it to matrix m = np.matrix(m) print(m, type(m)) # identity array m = np.identity(3) print(m, type(m)) # fill it with nans m.fill(np.nan) print(m, type(m)) # create matrix from data m = np.matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print(m, type(m))
RE: help with matricies - buran - May-04-2020 Also, you may find this comparison between array and matrix interesting RE: help with matricies - ptnb - May-04-2020 Thanks for quick answers. So, numpy it is...:) RE: help with matricies - buran - May-04-2020 (May-04-2020, 04:41 PM)ptnb Wrote: So, numpy it is...:)well, it was you who said that is using numpy :-) (May-04-2020, 01:56 PM)ptnb Wrote: Now, I know I can use NymPy |