in Education by
I want to test a 2x2 matrix of [[5,6],[7,8]] to see if it's a square. I run my code and I'm supposed to get True but I got False instead... def square(sq): for element in sq: if element: return False return True JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you want to check whether a matrix is NxN, you can use: def isSquare (m): return all (len (row) == len (m) for row in m) As you said in your comment: if the length of all rows equals the number of rows.

Related questions

0 votes
    I want to multiply these two matrices using pure python. Input (M1 is 3*3 and Mt is a 3*2) M1 = ... But technically this should work. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have a fixed list of services in a Linux server. I want to check the status of these services ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    R square value close to zero indicates a good fit. State if it is true or false? (1)True (2)False...
asked Aug 17, 2021 by JackTerrance
0 votes
    I am writing a Python script in Windows. I want to do something based on the file size. For example, if the ... I check the file size? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    How to check which Python version is interpreting my script? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    How can I check a given object is of a given type? How can I check that a object inherit a given type? There's ... that it's a string? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Forming a matrix by summing 2 arrays element-array wise using NumPy ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Forming a matrix by summing 2 arrays element-array wise using NumPy ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I have the 4D array, which is defined as follows: B = np.array( [[[[0.5000, 0.5625], [0.5000, ... loops and ideally one function call. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    suppose I have passed : list=[] How can I check if a list is empty or not? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Can someone tell me a method to check how can I represent a string as a number in Python? I am using this ... please help me with it. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    How can I check if a key exists in a directory in Python, before updating the value of the key. I tried this ... better way to do this? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I have the pandas data frame with a column designated to town names. After each town name, I am adding a word " ... .csv', index=False) Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have the pandas data frame with the column designated to town names. After each town name, I am adding a word ... .csv', index=False) Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    A 2 2 square matrix is written down at random using the number 1, -1 as elements. The probability that the matrix is ... 5/8 D. 1/3 Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
...