Create a numpy matrix with elements as a function of indices

前端 未结 5 928
迷失自我
迷失自我 2020-12-16 21:11

How can I create a numpy matrix with its elements being a function of its indices? For example, a multiplication table: a[i,j] = i*j

An Un-numpy and un-

5条回答
  •  悲哀的现实
    2020-12-16 21:50

    I'm away from my python at the moment, but does this one work?

    array( [ [ i*j for j in xrange(5)] for i in xrange(5)] )
    

提交回复
热议问题