百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 编程字典 > 正文

计算机视觉:mAP计算(计算机视觉api)

toyiye 2024-09-06 00:09 4 浏览 0 评论

本文[1]中,我们将了解如何使用 precision 和召回率来计算平均精度 (mAP)。mAP 将真实边界框与检测到的框进行比较并返回分数。分数越高,模型的检测越准确。

之前我们详细研究了混淆矩阵、模型准确性、精确度和召回率。我们也使用 Scikit-learn 库来计算这些指标。现在我们将扩展讨论以了解如何使用精度和召回率来计算 mAP

1. 从预测分数到类别标签

在本节中,我们将快速回顾一下如何从预测分数中派生出类标签。鉴于有两个类别,正类和负类,这里是 10 个样本的真实标签。

y_true = ["positive", "negative", "negative", "positive", "positive", "positive", "negative", "positive", "negative", "positive"]

当这些样本被输入模型时,它会返回以下预测分数。基于这些分数,我们如何对样本进行分类(即为每个样本分配一个类标签)?

pred_scores = [0.7, 0.3, 0.5, 0.6, 0.55, 0.9, 0.4, 0.2, 0.4, 0.3]

为了将分数转换为类别标签,使用了一个阈值。当分数等于或高于阈值时,样本被归为一类。否则,它被归类为其他类别。如果样本的分数高于或等于阈值,则该样本为阳性。否则,它是负面的。下一个代码块将分数转换为阈值为 0.5 的类别标签。

import numpy

pred_scores = [0.7, 0.3, 0.5, 0.6, 0.55, 0.9, 0.4, 0.2, 0.4, 0.3]
y_true = ["positive", "negative", "negative", "positive", "positive", "positive", "negative", "positive", "negative", "positive"]

threshold = 0.5
y_pred = ["positive" if score >= threshold else "negative" for score in pred_scores]
print(y_pred)
  • y_pred
['positive', 'negative', 'positive', 'positive', 'positive', 'positive', 'negative', 'negative', 'negative', 'negative']

现在 y_truey_pred 变量中都提供了真实标签和预测标签。基于这些标签,可以计算混淆矩阵、精度和召回率。

r = numpy.flip(sklearn.metrics.confusion_matrix(y_true, y_pred))
print(r)

precision = sklearn.metrics.precision_score(y_true=y_true, y_pred=y_pred, pos_label="positive")
print(precision)

recall = sklea
  • 结果
# Confusion Matrix (From Left to Right & Top to Bottom: True Positive, False Negative, False Positive, True Negative)
[[4 2]
 [1 3]]

# Precision = 4/(4+1)
0.8

# Recall = 4/(4+2)
0.6666666666666666

在快速回顾了计算准确率和召回率之后,在下一节中我们将讨论创建准确率-召回率曲线。

2. PR 曲线

根据第 1 部分给出的精度和召回率的定义,请记住精度越高,模型将样本分类为正时的置信度就越高。召回率越高,模型正确分类为正的正样本就越多

当一个模型的召回率高但精度低时,该模型会正确分类大部分正样本,但它有很多误报(即将许多负样本分类为正样本)。当模型具有高精度但召回率低时,模型将样本分类为正样本时是准确的,但它可能仅对部分正样本进行分类。

由于精度和召回率的重要性,精度-召回率曲线显示了不同阈值的精度和召回率值之间的权衡。该曲线有助于选择最佳阈值以最大化两个指标。

创建精确-召回曲线需要一些输入:

  1. 真实标签。
  2. 样本的预测分数。
  3. 将预测分数转换为类别标签的一些阈值。

下面的代码块创建 y_true 列表来保存真实标签,pred_scores 列表用于预测分数,最后是不同阈值的阈值列表。

import numpy

y_true = ["positive", "negative", "negative", "positive", "positive", "positive", "negative", "positive", "negative", "positive", "positive", "positive", "positive", "negative", "negative", "negative"]

pred_scores = [0.7, 0.3, 0.5, 0.6, 0.55, 0.9, 0.4, 0.2, 0.4, 0.3, 0.7, 0.5, 0.8, 0.2, 0.3, 0.35]

以下是保存在阈值列表中的阈值。因为有 10 个阈值,所以将创建 10 个精度和召回值。

[0.2, 
 0.25, 
 0.3, 
 0.35, 
 0.4, 
 0.45, 
 0.5, 
 0.55, 
 0.6, 
 0.65]

下面是名为 precision_recall_curve() 的函数,其接受真实标签、预测分数和阈值。它返回两个代表精度和召回值的等长列表。

import sklearn.metrics

def precision_recall_curve(y_true, pred_scores, thresholds):
    precisions = []
    recalls = []
    
    for threshold in thresholds:
        y_pred = ["positive" if score >= threshold else "negative" for score in pred_scores]

        precision = sklearn.metrics.precision_score(y_true=y_true, y_pred=y_pred, pos_label="positive")
        recall = sklearn.metrics.recall_score(y_true=y_true, y_pred=y_pred, pos_label="positive")
        
        precisions.append(precision)
        recalls.append(recall)

    return precisions, recalls

下一段代码在三个先前准备好的列表后调用 precision_recall_curve() 函数。它返回精度和召回列表,分别包含精度和召回的所有值。

precisions, recalls = precision_recall_curve(y_true=y_true, 
                                             pred_scores=pred_scores,
                                             thresholds=thresholds)
  • 以下是精度列表中的返回值。
[0.5625,
 0.5714285714285714,
 0.5714285714285714,
 0.6363636363636364,
 0.7,
 0.875,
 0.875,
 1.0,
 1.0,
 1.0]
  • 这是召回列表中的值列表。
[1.0,
 0.8888888888888888,
 0.8888888888888888,
 0.7777777777777778,
 0.7777777777777778,
 0.7777777777777778,
 0.7777777777777778,
 0.6666666666666666,
 0.5555555555555556,
 0.4444444444444444]

给定两个长度相等的列表,可以在二维图中绘制它们的值,如下所示。

matplotlib.pyplot.plot(recalls, precisions, linewidth=4, color="red")
matplotlib.pyplot.xlabel("Recall", fontsize=12, fontweight='bold')
matplotlib.pyplot.ylabel("Precision", fontsize=12, fontweight='bold')
matplotlib.pyplot.title("Precision-Recall Curve", fontsize=15, fontweight="bold")
matplotlib.pyplot.show()

准确率-召回率曲线如下图所示。请注意,随着召回率的增加,精度会降低。原因是当正样本数量增加(高召回率)时,正确分类每个样本的准确率降低(低精度)。这是预料之中的,因为当有很多样本时,模型更有可能预测出错。

准确率-召回率曲线可以很容易地确定准确率和召回率都高的点。根据上图,最好的点是(recall, precision)=(0.778, 0.875)。

使用上图以图形方式确定精度和召回率的最佳值可能有效,因为曲线并不复杂。更好的方法是使用称为 f1 分数的指标,它是根据下一个等式计算的。

f1 指标衡量准确率和召回率之间的平衡。当 f1 的值很高时,这意味着精度和召回率都很高。较低的 f1 分数意味着精确度和召回率之间的失衡更大。

根据前面的例子,f1 是根据下面的代码计算的。根据 f1 列表中的值,最高分是 0.82352941。它是列表中的第 6 个元素(即索引 5)。召回率和精度列表中的第 6 个元素分别为 0.778 和 0.875。相应的阈值为 0.45。

f1 = 2 * ((numpy.array(precisions) * numpy.array(recalls)) / (numpy.array(precisions) + numpy.array(recalls)))

下图以蓝色显示了与召回率和准确率之间的最佳平衡相对应的点的位置。总之,平衡精度和召回率的最佳阈值是 0.45,此时精度为 0.875,召回率为 0.778。

matplotlib.pyplot.plot(recalls, precisions, linewidth=4, color="red", zorder=0)
matplotlib.pyplot.scatter(recalls[5], precisions[5], zorder=1, linewidth=6)

matplotlib.pyplot.xlabel("Recall", fontsize=12, fontweight='bold')
matplotlib.pyplot.ylabel("Precision", fontsize=12, fontweight='bold')
matplotlib.pyplot.title("Precision-Recall Curve", fontsize=15, fontweight="bold")
matplotlib.pyplot.show()

3. AP

平均精度 (AP) 是一种将精度召回曲线汇总为表示所有精度平均值的单个值的方法。根据面等式计算 AP。使用遍历所有精度/召回率的循环,计算当前召回率和下一次召回率之间的差异,然后乘以当前精度。换句话说,AP 是每个阈值的精度加权和,其中权重是召回率的增加。

AP

分别在召回率和准确率列表上附加 0 和 1 很重要。例如,如果召回列表为 0.8、0.60.8、0.6,则应在 0.8、0.6、0.00.8、0.6、0.0 后附加 0。精度列表也是如此,但附加了 1 而不是 0(例如 0.8、0.2、1.00.8、0.2、1.0)。

鉴于召回率和精度都是 NumPy 数组,前面的等式根据下面 Python 代码建模。

AP = numpy.sum((recalls[:-1] - recalls[1:]) * precisions[:-1])
  • 这是计算 AP 的完整代码。
import numpy
import sklearn.metrics

def precision_recall_curve(y_true, pred_scores, thresholds):
    precisions = []
    recalls = []
    
    for threshold in thresholds:
        y_pred = ["positive" if score >= threshold else "negative" for score in pred_scores]

        precision = sklearn.metrics.precision_score(y_true=y_true, y_pred=y_pred, pos_label="positive")
        recall = sklearn.metrics.recall_score(y_true=y_true, y_pred=y_pred, pos_label="positive")
        
        precisions.append(precision)
        recalls.append(recall)

    return precisions, recalls

y_true = ["positive", "negative", "negative", "positive", "positive", "positive", "negative", "positive", "negative", "positive", "positive", "positive", "positive", "negative", "negative", "negative"]
pred_scores = [0.7, 0.3, 0.5, 0.6, 0.55, 0.9, 0.4, 0.2, 0.4, 0.3, 0.7, 0.5, 0.8, 0.2, 0.3, 0.35]
thresholds=numpy.arange(start=0.2, stop=0.7, step=0.05)

precisions, recalls = precision_recall_curve(y_true=y_true, 
                                             pred_scores=pred_scores, 
                                             thresholds=thresholds)

precisions.append(1)
recalls.append(0)

precisions = numpy.array(precisions)
recalls = numpy.array(recalls)

AP = numpy.sum((recalls[:-1] - recalls[1:]) * precisions[:-1])
print(AP)
  • 这都是关于平均精度的。以下是计算 AP 的步骤摘要:
  1. 使用模型生成预测分数。
  2. 将预测分数转换为类别标签。
  3. 计算混淆矩阵。
  4. 计算精度和召回率指标。
  5. 创建精确召回曲线。
  6. 测量平均精度。

4. IoU

要训练目标检测模型,通常有 2 个输入:

  1. 图片
  2. 图像检测结果的真实框

该模型预测检测到的对象的边界框。预计预测框不会与真实框完全匹配。下图显示了猫的图像。对象的真实框为红色,而预测框为黄色。基于 2 个框的可视化,模型是否做出了高匹配分数的良好预测?

很难主观地评估模型预测。例如,有人可能会得出匹配率为 50% 的结论,而其他人则注意到匹配率为 60%。

更好的替代方法是使用定量测量来对真实框和预测框的匹配程度进行评分。此度量是交并集 (IoU)。 IoU 有助于了解一个区域是否有对象。

IoU 是根据下面等式计算的,通过将 2 个框之间的交叉区域除以它们的联合区域。 IoU 越高,预测越好。

IoU

下图显示了具有不同 IoU 的 3 个案例。请注意,每个案例顶部的 IoU 都是客观测量的,可能与现实略有不同,但它是有道理的。 对于案例 A,预测的黄色框远未与红色真值框对齐,因此 IoU 得分为 0.2(即两个框之间只有 20% 的重叠)。 对于情况 B,2 个框之间的交叉区域更大,但 2 个框仍然没有很好地对齐,因此 IoU 分数为 0.5。 对于案例 C,两个框的坐标非常接近,因此它们的 IoU 为 0.9(即两个框之间有 90% 的重叠)。 请注意,当预测框和真实框之间的重叠率为 0% 时,IoU 为 0.0。当 2 个框彼此 100% 匹配时,IoU 为 1.0。

ABC

要计算图像的 IoU,这里有一个名为 intersection_over_union() 的函数。它接受以下 2 个参数:

  1. gt_box:真实边界框。
  2. pred_box:预测边界框。

它分别计算交集和并集变量中两个框之间的交集和并集。此外,IoU 是在 iou 变量中计算的。它返回所有这 3 个变量。

def intersection_over_union(gt_box, pred_box):
    inter_box_top_left = [max(gt_box[0], pred_box[0]), max(gt_box[1], pred_box[1])]
    inter_box_bottom_right = [min(gt_box[0]+gt_box[2], pred_box[0]+pred_box[2]), min(gt_box[1]+gt_box[3], pred_box[1]+pred_box[3])]

    inter_box_w = inter_box_bottom_right[0] - inter_box_top_left[0]
    inter_box_h = inter_box_bottom_right[1] - inter_box_top_left[1]

    intersection = inter_box_w * inter_box_h
    union = gt_box[2] * gt_box[3] + pred_box[2] * pred_box[3] - intersection
    
    iou = intersection / union

    return iou, intersection, union

传递给函数的边界框是一个包含 4 个元素的列表,它们是:

  1. 左上角的 x 轴。
  2. 左上角的 y 轴。

这是汽车图像的真实边界框和预测边界框。

gt_box = [320, 220, 680, 900]
pred_box = [500, 320, 550, 700]

图像名为 cat.jpg,下面是在图像上绘制边界框的完整示例。

import imageio
import matplotlib.pyplot
import matplotlib.patches

def intersection_over_union(gt_box, pred_box):
    inter_box_top_left = [max(gt_box[0], pred_box[0]), max(gt_box[1], pred_box[1])]
    inter_box_bottom_right = [min(gt_box[0]+gt_box[2], pred_box[0]+pred_box[2]), min(gt_box[1]+gt_box[3], pred_box[1]+pred_box[3])]

    inter_box_w = inter_box_bottom_right[0] - inter_box_top_left[0]
    inter_box_h = inter_box_bottom_right[1] - inter_box_top_left[1]

    intersection = inter_box_w * inter_box_h
    union = gt_box[2] * gt_box[3] + pred_box[2] * pred_box[3] - intersection
    
    iou = intersection / union

    return iou, intersection, union

im = imageio.imread("cat.jpg")

gt_box = [320, 220, 680, 900]
pred_box = [500, 320, 550, 700]

fig, ax = matplotlib.pyplot.subplots(1)
ax.imshow(im)

gt_rect = matplotlib.patches.Rectangle((gt_box[0], gt_box[1]),
                                       gt_box[2],
                                       gt_box[3],
                                       linewidth=5,
                                       edgecolor='r',
                                       facecolor='none')

pred_rect = matplotlib.patches.Rectangle((pred_box[0], pred_box[1]),
                                         pred_box[2],
                                         pred_box[3],
                                         linewidth=5,
                                         edgecolor=(1, 1, 0),
                                         facecolor='none')
ax.add_patch(gt_rect)
ax.add_patch(pred_rect)

ax.axes.get_xaxis().set_ticks([])
ax.axes.get_yaxis().set_ticks([])

下图显示了带有边界框的图像。

要计算 IoU,只需调用 intersection_over_union() 函数。基于边界框,IoU 得分为 0.54。

iou, intersect, union = intersection_over_union(gt_box, pred_box)
print(iou, intersect, union)
  • 结果

IoU 分数 0.54 意味着真实边界框和预测边界框之间有 54% 的重叠。看着方框,有人可能在视觉上觉得它足以得出模型检测到猫对象的结论。其他人可能会觉得模型还不准确,因为预测框与真实框不太吻合。

为了客观地判断模型是否正确预测了框的位置,使用了一个阈值。如果模型预测 IoU 分数大于或等于阈值的框,则预测框与其中一个真实框之间存在高度重叠。这意味着该模型能够成功检测到一个对象。检测到的区域被归类为阳性(即包含一个对象)。

另一方面,当 IoU 分数小于阈值时,模型做出了错误的预测,因为预测框与真实框不重叠。这意味着检测到的区域被归类为负面(即不包含对象)。

让我们举个例子来阐明 IoU 分数如何帮助将区域分类为对象。假设对象检测模型由下一张图像提供,其中有 2 个目标对象,其真实框为红色,预测框为黄色。 下一个代码读取图像(假设它被命名为 pets.jpg),绘制框,并计算每个对象的 IoU。左侧对象的 IoU 为 0.76,而另一个对象的 IoU 分数为 0.26。

import matplotlib.pyplot
import matplotlib.patches
import imageio

def intersection_over_union(gt_box, pred_box):
    inter_box_top_left = [max(gt_box[0], pred_box[0]), max(gt_box[1], pred_box[1])]
    inter_box_bottom_right = [min(gt_box[0]+gt_box[2], pred_box[0]+pred_box[2]), min(gt_box[1]+gt_box[3], pred_box[1]+pred_box[3])]

    inter_box_w = inter_box_bottom_right[0] - inter_box_top_left[0]
    inter_box_h = inter_box_bottom_right[1] - inter_box_top_left[1]

    intersection = inter_box_w * inter_box_h
    union = gt_box[2] * gt_box[3] + pred_box[2] * pred_box[3] - intersection
    
    iou = intersection / union

    return iou, intersection, union, 

im = imageio.imread("pets.jpg")

gt_box = [10, 130, 370, 350]
pred_box = [30, 100, 370, 350]

iou, intersect, union = intersection_over_union(gt_box, pred_box)
print(iou, intersect, union)

fig, ax = matplotlib.pyplot.subplots(1)
ax.imshow(im)

gt_rect = matplotlib.patches.Rectangle((gt_box[0], gt_box[1]),
                                       gt_box[2],
                                       gt_box[3],
                                       linewidth=5,
                                       edgecolor='r',
                                       facecolor='none')

pred_rect = matplotlib.patches.Rectangle((pred_box[0], pred_box[1]),
                                         pred_box[2],
                                         pred_box[3],
                                         linewidth=5,
                                         edgecolor=(1, 1, 0),
                                         facecolor='none')
ax.add_patch(gt_rect)
ax.add_patch(pred_rect)

gt_box = [645, 130, 310, 320]
pred_box = [500, 60, 310, 320]

iou, intersect, union = intersection_over_union(gt_box, pred_box)
print(iou, intersect, union)

gt_rect = matplotlib.patches.Rectangle((gt_box[0], gt_box[1]),
                                       gt_box[2],
                                       gt_box[3],
                                       linewidth=5,
                                       edgecolor='r',
                                       facecolor='none')

pred_rect = matplotlib.patches.Rectangle((pred_box[0], pred_box[1]),
                                         pred_box[2],
                                         pred_box[3],
                                         linewidth=5,
                                         edgecolor=(1, 1, 0),
                                         facecolor='none')
ax.add_patch(gt_rect)
ax.add_patch(pred_rect)

ax.axes.get_xaxis().set_ticks([])
ax.axes.get_yaxis().set_ticks([])

鉴于 IoU 阈值为 0.6,则只有 IoU 分数大于或等于 0.6 的区域被归类为正(即有物体)。因此,IoU 得分为 0.76 的框为正,而另一个 IoU 为 0.26 的框为负。

如果阈值更改为 0.2 而不是 0.6,则两个预测都是Positive的。如果阈值为 0.8,则两个预测都是负面的。

作为总结,IoU 分数衡量预测框与真实框的接近程度。它的范围从 0.0 到 1.0,其中 1.0 是最佳结果。当 IoU 大于阈值时,该框被分类为正,因为它围绕着一个对象。否则,它被归类为负面。

5. mAP

通常,目标检测模型使用不同的 IoU 阈值进行评估,其中每个阈值可能给出与其他阈值不同的预测。假设模型由一个图像提供,该图像具有分布在 2 个类中的 10 个对象。如何计算mAP?

要计算 mAP,首先要计算每个类的 AP。所有类别的 AP 的平均值是 mAP。

假设使用的数据集只有 2 个类。对于第一类,这里分别是 y_truepred_scores 变量中的真实标签和预测分数。

y_true = ["positive", "negative", "positive", "negative", "positive", "positive", "positive", "negative", "positive", "negative"]

pred_scores = [0.7, 0.3, 0.5, 0.6, 0.55, 0.9, 0.75, 0.2, 0.8, 0.3]

这是第二类的 y_truepred_scores 变量。

y_true = ["negative", "positive", "positive", "negative", "negative", "positive", "positive", "positive", "negative", "positive"]

pred_scores = [0.32, 0.9, 0.5, 0.1, 0.25, 0.9, 0.55, 0.3, 0.35, 0.85]

IoU 阈值列表从 0.2 到 0.9,步长为 0.25。

thresholds = numpy.arange(start=0.2, stop=0.9, step=0.05)

要计算一个类的 AP,只需将其 y_truepred_scores 变量提供给下一个代码。

precisions, recalls = precision_recall_curve(y_true=y_true, 
                                             pred_scores=pred_scores, 
                                             thresholds=thresholds)

matplotlib.pyplot.plot(recalls, precisions, linewidth=4, color="red", zorder=0)

matplotlib.pyplot.xlabel("Recall", fontsize=12, fontweight='bold')
matplotlib.pyplot.ylabel("Precision", fontsize=12, fontweight='bold')
matplotlib.pyplot.title("Precision-Recall Curve", fontsize=15, fontweight="bold")
matplotlib.pyplot.show()

precisions.append(1)
recalls.append(0)

precisions = numpy.array(precisions)
recalls = numpy.array(recalls)

AP = numpy.sum((recalls[:-1] - recalls[1:]) * precisions[:-1])
print(AP)

对于第一类,这是它的精确召回曲线。基于此曲线,AP 为 0.949。

第二类的precision-recall曲线如下图所示。它的 AP 是 0.958。

基于 2 个类(0.949 和 0.958)的 AP,根据下面等式计算目标检测模型的 mAP

基于此等式,mAP 为 0.9535。

mAP = (0.949 + 0.958)/2 = 0.9535

总结

本教程讨论了如何计算目标检测模型的平均精度 (mAP)。我们首先讨论如何将预测分数转换为类别标签。使用不同的阈值,创建精确召回曲线。从该曲线可以测量平均精度 (AP)。

对于目标检测模型,阈值是对检测到的对象进行评分的 IoU。一旦为数据集中的每个类测量了 AP,就会计算出 mAP。


参考资料

[1]Source: https://www.kdnuggets.com/2021/03/evaluating-object-detection-models-using-mean-average-precision.html

相关推荐

# Python 3 # Python 3字典Dictionary(1)

Python3字典字典是另一种可变容器模型,且可存储任意类型对象。字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中,格式如...

Python第八课:数据类型中的字典及其函数与方法

Python3字典字典是另一种可变容器模型,且可存储任意类型对象。字典的每个键值...

Python中字典详解(python 中字典)

字典是Python中使用键进行索引的重要数据结构。它们是无序的项序列(键值对),这意味着顺序不被保留。键是不可变的。与列表一样,字典的值可以保存异构数据,即整数、浮点、字符串、NaN、布尔值、列表、数...

Python3.9又更新了:dict内置新功能,正式版十月见面

机器之心报道参与:一鸣、JaminPython3.8的热乎劲还没过去,Python就又双叒叕要更新了。近日,3.9版本的第四个alpha版已经开源。从文档中,我们可以看到官方透露的对dic...

Python3 基本数据类型详解(python三种基本数据类型)

文章来源:加米谷大数据Python中的变量不需要声明。每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。在Python中,变量就是变量,它没有类型,我们所说的"类型"是变...

一文掌握Python的字典(python字典用法大全)

字典是Python中最强大、最灵活的内置数据结构之一。它们允许存储键值对,从而实现高效的数据检索、操作和组织。本文深入探讨了字典,涵盖了它们的创建、操作和高级用法,以帮助中级Python开发...

超级完整|Python字典详解(python字典的方法或操作)

一、字典概述01字典的格式Python字典是一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型。字典的每个键值key=>value对用冒号:分割,每个对之间用逗号,...

Python3.9版本新特性:字典合并操作的详细解读

处于测试阶段的Python3.9版本中有一个新特性:我们在使用Python字典时,将能够编写出更可读、更紧凑的代码啦!Python版本你现在使用哪种版本的Python?3.7分?3.5分?还是2.7...

python 自学,字典3(一些例子)(python字典有哪些基本操作)

例子11;如何批量复制字典里的内容2;如何批量修改字典的内容3;如何批量修改字典里某些指定的内容...

Python3.9中的字典合并和更新,几乎影响了所有Python程序员

全文共2837字,预计学习时长9分钟Python3.9正在积极开发,并计划于今年10月发布。2月26日,开发团队发布了alpha4版本。该版本引入了新的合并(|)和更新(|=)运算符,这个新特性几乎...

Python3大字典:《Python3自学速查手册.pdf》限时下载中

最近有人会想了,2022了,想学Python晚不晚,学习python有前途吗?IT行业行业薪资高,发展前景好,是很多求职群里严重的香饽饽,而要进入这个高薪行业,也不是那么轻而易举的,拿信工专业的大学生...

python学习——字典(python字典基本操作)

字典Python的字典数据类型是基于hash散列算法实现的,采用键值对(key:value)的形式,根据key的值计算value的地址,具有非常快的查取和插入速度。但它是无序的,包含的元素个数不限,值...

324页清华教授撰写【Python 3 菜鸟查询手册】火了,小白入门字典

如何入门学习python...

Python3.9中的字典合并和更新,了解一下

全文共2837字,预计学习时长9分钟Python3.9正在积极开发,并计划于今年10月发布。2月26日,开发团队发布了alpha4版本。该版本引入了新的合并(|)和更新(|=)运算符,这个新特性几乎...

python3基础之字典(python中字典的基本操作)

字典和列表一样,也是python内置的一种数据结构。字典的结构如下图:列表用中括号[]把元素包起来,而字典是用大括号{}把元素包起来,只不过字典的每一个元素都包含键和值两部分。键和值是一一对应的...

取消回复欢迎 发表评论:

请填写验证码