Back
I'm trying to break down a program line by line. Y is a matrix of data but I can't find any concrete data on what .shape[0] does exactly.
for i in range(Y.shape[0]): if Y[i] == -1:
for i in range(Y.shape[0]):
if Y[i] == -1:
This program uses numpy, scipy, matplotlib.pyplot, and cvxopt.
The shape attribute for numpy arrays returns the dimensions of the array. If Y has n rows and m columns, then Y.shape is (n,m). So Y.shape[0] is n.
>>Y = np.arange(12).reshape(3,4) >>print(Y) array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>Y.shape (3, 4) >>Y.shape[0] 3
>>Y = np.arange(12).reshape(3,4)
>>print(Y)
array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]])
>>Y.shape
(3, 4)
>>Y.shape[0]
3
To know more about this you can have a look at the following video tutorial:-
31k questions
32.8k answers
501 comments
693 users