[英]create matrix whose position value is given by a function
I have to create a 5X5 matrix from a function given below.我必须从下面给出的 function 创建一个 5X5 矩阵。
f(x,y) = x(1-y) + y(1-x); f(x,y) = x(1-y) + y(1-x); where 0 < x,y <=5其中 0 < x,y <=5
where x indicate row position and y indicates columns.其中 x 表示行 position 并且 y 表示列。 How do I create a matrix such that bottom left corner is f(0,0) and top left corner has value f(5,5)如何创建一个矩阵,使左下角为 f(0,0),左上角的值为 f(5,5)
M,N = 5,5
matrix = [[((x*(1-y))+(y*(1-x))) for y in range(M)] for x in range(N)]
for i in range(N):
print(matrix[i])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.