Iterating over Numpy matrix rows to apply a function each?

前端 未结 3 1427
囚心锁ツ
囚心锁ツ 2020-12-02 09:27

I want to be able to iterate over the matrix to apply a function to each row. How can I do it for a Numpy matrix ?

3条回答
  •  借酒劲吻你
    2020-12-02 09:46

    While you should certainly provide more information, if you are trying to go through each row, you can just iterate with a for loop:

    import numpy
    m = numpy.ones((3,5),dtype='int')
    for row in m:
      print str(row)
    

提交回复
热议问题