Numpy 的 diagflat(~)
方法创建一个 2D Numpy 数组,其对角线由展平的输入数组指定。所有其他条目均用零填充。
参数
1. a
| array-like
输入数组。多维数组将自动展平为一维。
2. k
| int
| optional
如果 k 为正,则顶部的对角线将被填充。如果为负,则底部的对角线将被填充。默认情况下,k=0
。
返回值
二维 Numpy 数组。
例子
基本用法
考虑以下二维数组:
np.diagflat([4,5,6])
array([[4, 0, 0],
[0, 5, 0],
[0, 0, 6]])
指定偏移量
np.diagflat([4,5,6], k=1)
array([[0, 4, 0, 0],
[0, 0, 5, 0],
[0, 0, 0, 6],
[0, 0, 0, 0]])
np.diagflat([4,5], k=1)
array([[0, 4, 0],
[0, 0, 5],
[0, 0, 0]])
np.diagflat([4,5], k=-1)
array([[0, 0, 0],
[4, 0, 0],
[0, 5, 0]])
相关用法
- Python NumPy diagonal方法用法及代码示例
- Python NumPy diag方法用法及代码示例
- Python distributed.protocol.serialize.register_generic用法及代码示例
- Python distributed.get_task_metadata用法及代码示例
- Python distributed.Client.gather用法及代码示例
- Python distributed.recreate_tasks.ReplayTaskClient.recreate_task_locally用法及代码示例
- Python distributed.diagnostics.plugin.SchedulerPlugin用法及代码示例
- Python distributed.Client.ncores用法及代码示例
- Python distributed.Client.retire_workers用法及代码示例
- Python distributed.Client.unregister_worker_plugin用法及代码示例
- Python distributed.fire_and_forget用法及代码示例
- Python dir用法及代码示例
- Python distributed.Client.set_metadata用法及代码示例
- Python dictionary cmp()用法及代码示例
- Python distributed.Client.scheduler_info用法及代码示例
- Python distributed.Client.submit用法及代码示例
- Python distributed.Client.compute用法及代码示例
- Python distributed.SpecCluster.scale用法及代码示例
- Python distributed.get_worker用法及代码示例
- Python distributed.SpecCluster.scale_up用法及代码示例
- Python difflib.unified_diff用法及代码示例
- Python distributed.Client.nthreads用法及代码示例
- Python distributed.comm.resolve_address用法及代码示例
- Python distributed.Client.unpublish_dataset用法及代码示例
- Python distributed.get_task_stream用法及代码示例
注:本文由纯净天空筛选整理自Isshin Inada大神的英文原创作品 NumPy | diagflat method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。