I am studying python on my own and I want to create a matrix; by reading in the internet I found many ways to define a matrix and I decided to select these 2 methodologies:
import numpy as np
# Method 1
w, h = 5, 5
M = [[0 for x in range(w)] for y in range(h)]
M[1][2] = 100 # ok
m = M[:,2] # <----- Why is it not possible?
# Method 2
A = np.zeros((5, 5))
A[1][2] = 100 # ok
a = A[:,2] # <----- Why is it possible?
In both cases I am able to construct the matrix but the problem arises when I try to define an array by selecting one column of the matrix itself. While in the second case I am able to define a I cannot do the same thing for m; what am I doing wrong?
What should I do in order to extract a column out of M?
I believe the reason resides in the fact that M and A are not the same type of variable but honestly I don't understand the difference and therefore I don't know how to proceed.
<class 'list'> # M
<class 'numpy.ndarray'> # A
m = [sub[2] for sub in M]M = np.array(M)to convert that list into a numpy array and you can use the second method.