defis_product_availability_matrix(matrix_a, matrix_b):
row_a = [row for row in matrix_a]
column_b = [column for column in zip(*matrix_b)]
if(len(row_a) == len(column_b)):
result = True
else:
result = False
return result
matrix_x= [[2, 5], [1, 1]]
matrix_y = [[1, 1, 2], [2, 1, 1]]
matrix_z = [[2, 4], [5, 3], [1, 3]]
print(is_product_availability_matrix(matrix_y, matrix_z)) # # True
print(is_product_availability_matrix(matrix_z, matrix_x)) # # True
print(is_product_availability_matrix(matrix_z, matrix_w)) # False
print(is_product_availability_matrix(matrix_x, matrix_x)) # # True
If you look at the 3rd print, there is a false error when you deliver a value that does not have matrix_w as a factor, and I want to get false as a return value. What should I do?
python matrix function
NameError occurs because there are no variables.
NameError exception handling is typically available.
However, for simple actions such as questions,
print(is_product_availability_matrix(matrix_z, matrix_w if 'matrix_w' in locals() else []))
It can be handled as shown in .
Check whether the local variable exists or not, and forward an empty list.
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
581 PHP ssh2_scp_send fails to send files as intended
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.