简体   繁体   中英

create matrix whose position value is given by a function

I have to create a 5X5 matrix from a function given below.

f(x,y) = x(1-y) + y(1-x); where 0 < x,y <=5

where x indicate row position and y indicates columns. How do I create a matrix such that bottom left corner is f(0,0) and top left corner has value 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])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM