首页 > 行业资讯 > NumPy教程-numpy.matlib.identity()

NumPy教程-numpy.matlib.identity()

时间:2023-11-18 来源: 浏览:

NumPy教程-numpy.matlib.identity()

点击关注 Python架构师
Python架构师

gh_1d7504e4dee1

回复:python,领取Python面试题。分享Python教程,Python架构师教程,Python爬虫,Python编程视频,Python脚本,Pycharm教程,Python微服务架构,Python分布式架构,Pycharm注册码。

收录于合集
#numpy 65
#NumPy教程 65
#python web教程 125
#python教程 213
#NumPy 65
整理: python架构师

这个函数用于返回一个给定尺寸的单位矩阵。单位矩阵是对角线元素初始化为1,其他元素为零的矩阵。

语法

numpy .matlib .ones ( size , dtype )

参数

它接受以下参数。

  1. shape: 生成的单位矩阵的行数和列数。

  2. dtype: 单位矩阵的数据类型。

返回值

它返回一个指定尺寸和指定数据类型的单位矩阵。

资源分享

点击领取:最全Python资料合集

示例

import numpy as np import numpy.matlib print (numpy.matlib.identity( 4 ))

输出:

[[ 1. 0. 0. 0. ] [ 0. 1. 0. 0. ] [ 0. 0. 1. 0. ] [ 0. 0. 0. 1. ]]

示例:具有整数值的单位矩阵

import numpy as np import numpy.matlib print (numpy.matlib.identity( 4 ,int))

输出:

[[ 1 0 0 0 ] [ 0 1 0 0 ] [ 0 0 1 0 ] [ 0 0 0 1 ]]

 
热门推荐
  • 风波回顾:阿里云抽风,全线产品玩“躺平”!

  • NumPy教程-numpy.matlib.eye()

  • 我写的bug,养活了公司6个测试

版权:如无特殊注明,文章转载自网络,侵权请联系cnmhg168#163.com删除!文件均为网友上传,仅供研究和学习使用,务必24小时内删除。
相关推荐