How to create identity matrix with numpy

前端 未结 3 2530
走了就别回头了
走了就别回头了 2021-02-20 08:39

How do I create an identity matrix with numpy? Is there a simpler syntax than

numpy.matrix(numpy.identity(n))
3条回答
  •  遥遥无期
    2021-02-20 09:33

    I don't think there is a simpler solution. You can do it slightly more efficiently, though:

    numpy.matrix(numpy.identity(n), copy=False)
    

    This avoids unnecessarily copying the data.

提交回复
热议问题