📜  Python| numpy matrix.put()

📅  最后修改于: 2022-05-13 01:55:31.996000             🧑  作者: Mango

Python| numpy matrix.put()

借助Numpy matrix.put()方法,我们可以通过在给定矩阵中传递索引和值来放置

示例 #1:
在这个例子中,我们可以看到我们能够在方法matrix.put()的帮助下将值放入给定的矩阵中。

# import the important module in python
import numpy as np
          
# make matrix with numpy
gfg = np.matrix('[64, 1; 12, 3]')
          
# applying matrix.put() method
gfg.put((0, 1), 45)
    
print(gfg)
输出:
[[45 45]
 [12  3]]

示例 #2:

# import the important module in python
import numpy as np
          
# make a matrix with numpy
gfg = np.matrix('[1, 2, 3; 4, 5, 6; 7, 8, -9]')
          
# applying matrix.put() method
gfg.put(2, 43)
    
print(gfg)
输出:
[[ 1  2 43]
 [ 4  5  6]
 [ 7  8 -9]]