我们可以使用 atplotlib.rcParams['backend'] 变量覆盖后端值。步骤使用 get_backend() 方法,返回当前后端名称,即默认名称。现在覆盖后端名称。使用 get_backend() 方法,返回当前后端名称,即更新后的名称。示例import matplotlib print("Before, Backend used by matplotlib is: ", matplotlib.get_backend()) matplotlib.rcParams['backend'] = 'TkAgg' print("After, Backend used by matplotlib is: ", matplotlib.get_backend())输出Before, Backend used by matplotlib is: GTK3Agg After, Backend used by matplotlib is: TkAgg 输入条形图数量:5
我们将首先创建一个 numpy 矩阵,然后找出该矩阵的行数和列数算法步骤 1:创建一个随机数的 numpy 矩阵。步骤 2:使用 numpy.shape 函数查找矩阵的行和列。步骤 3:打印行数和列数。示例代码import numpy as np matrix = np.random.rand(2,3) print(matrix) print("Total number of rows and columns in the given matrix are: ", matrix.shape)输出[[0.23226052 0.89690884 0.19813164] [0.85170808 0.97725669 0.72454096]] Total number of rows and columns in the given matrix are: (2, 3)