当前位置: 首页 > news >正文

Python酷库之旅-第三方库Pandas(018)

目录

一、用法精讲

44、pandas.crosstab函数

44-1、语法

44-2、参数

44-3、功能

44-4、返回值

44-5、说明

44-6、用法

44-6-1、数据准备

44-6-2、代码示例

44-6-3、结果输出

45、pandas.cut函数

45-1、语法

45-2、参数

45-3、功能

45-4、返回值

45-5、说明

45-6、用法

45-6-1、数据准备

45-6-2、代码示例

45-6-3、结果输出 

46、pandas.qcut函数

46-1、语法

46-2、参数

46-3、功能

46-4、返回值

46-5、说明

46-6、用法

46-6-1、数据准备

46-6-2、代码示例

46-6-3、结果输出

二、推荐阅读

1、Python筑基之旅

2、Python函数之旅

3、Python算法之旅

4、Python魔法之旅

5、博客个人主页

一、用法精讲

44、pandas.crosstab函数
44-1、语法
# 44、pandas.crosstab函数
pandas.crosstab(index, columns, values=None, rownames=None, colnames=None, aggfunc=None, margins=False, margins_name='All', dropna=True, normalize=False)
Compute a simple cross tabulation of two (or more) factors.By default, computes a frequency table of the factors unless an array of values and an aggregation function are passed.Parameters:
index
array-like, Series, or list of arrays/Series
Values to group by in the rows.columns
array-like, Series, or list of arrays/Series
Values to group by in the columns.values
array-like, optional
Array of values to aggregate according to the factors. Requires aggfunc be specified.rownames
sequence, default None
If passed, must match number of row arrays passed.colnames
sequence, default None
If passed, must match number of column arrays passed.aggfunc
function, optional
If specified, requires values be specified as well.margins
bool, default False
Add row/column margins (subtotals).margins_name
str, default ‘All’
Name of the row/column that will contain the totals when margins is True.dropna
bool, default True
Do not include columns whose entries are all NaN.normalize
bool, {‘all’, ‘index’, ‘columns’}, or {0,1}, default False
Normalize by dividing all values by the sum of values.If passed ‘all’ or True, will normalize over all values.If passed ‘index’ will normalize over each row.If passed ‘columns’ will normalize over each column.If margins is True, will also normalize margin values.Returns:
DataFrame
Cross tabulation of the data.
44-2、参数

44-2-1、index(必须)用于交叉表的行索引的数组或序列,这通常是DataFrame中的一列或多列,用于确定交叉表的行。

44-2-2、columns(必须)用于交叉表的列索引的数组或序列,这同样是DataFrame中的一列或多列,用于确定交叉表的列。

44-2-3、values(可选,默认值为None)如果提供,它应该是DataFrame中的一列,其值将根据aggfunc参数指定的函数进行聚合,以填充交叉表的单元格;如果不提供,则默认计算每个组合中的观测数(即计数)。

44-2-4、rownames/colnames(可选,默认值为None)在较新版本的pandas中,这两个参数可能已被弃用或不再使用,它们原本用于为行和列索引提供自定义名称,但现在通常建议直接使用index和columns参数的列名作为行和列索引的名称。

44-2-5、aggfunc(可选,默认值为None)用于聚合values参数指定的值的函数,如果values为None,则默认为'count',即计算每个组合的观测数,其他函数有'sum'、'mean'、'max'、'min'等。

44-2-6、margins(可选,默认值为False)布尔值,如果为True,则会在交叉表的末尾添加一个全行/全列,包含所有值的聚合(基于aggfunc)。

44-2-7、margins_name(可选,默认值为'All')字符串,当margins=True时,用于命名全行/全列的标签。

44-2-8、dropna(可选,默认值为True)布尔值,如果为True,则会从结果中删除包含缺失值的行或列(取决于index和columns中的缺失值);如果为False,则包含缺失值的组合也会出现在交叉表中,但它们的值将取决于aggfunc和values的设置。

44-2-9、normalize(可选,默认值为False)布尔值或字符串('index'或'columns'),如果为True,则会对值进行归一化处理,使得每个行(或列,取决于归一化方式)的总和等于1;如果为'index',则对每行进行归一化;如果为'columns',则对每列进行归一化。

44-3、功能

        用于创建交叉表(也称为列联表或频数表)。

44-4、返回值

        返回值是一个新的DataFrame,该DataFrame展示了基于index和columns参数指定的行和列索引的交叉表。

44-5、说明

44-5-1、如果未指定values和aggfunc参数,则交叉表中的值默认为每个组合的观测数量。

44-5-2、如果指定了values和aggfunc参数,则交叉表中的值是根据aggfunc指定的聚合函数对values中的值进行聚合得到的结果。

44-5-3、如果margins参数为True,则返回的DataFrame还会包含一个额外的全行和/或全列(取决于margins的具体设置),用于显示所有行和/或列的总和。

44-5-4、如果normalize参数为True或'all',则交叉表中的值会被归一化,使得每行或每列(或整个交叉表)的总和等于 1;如果normalize为'index'或'columns',则分别对每行或每列进行归一化。

44-6、用法
44-6-1、数据准备
44-6-2、代码示例
# 44、pandas.crosstab函数
import pandas as pd
import numpy as np
# 创建一个示例数据集
data = {'Date': pd.date_range('2023-01-01', periods=6, freq='D'),'City': ['New York', 'Los Angeles', 'New York', 'Los Angeles', 'New York', 'Los Angeles'],'Category': ['A', 'A', 'B', 'B', 'A', 'B'],'Values': [100, 200, 150, 250, np.nan, 300]
}
df = pd.DataFrame(data)
print("原始数据集:")
print(df)
# 使用crosstab函数创建交叉表
crosstab_result = pd.crosstab(index=[df['Date'], df['City']],columns=df['Category'],values=df['Values'],rownames=['Date', 'City'],colnames=['Category'],aggfunc='sum',margins=True,margins_name='All',dropna=True,normalize=False
)
print("\ncrosstab结果:")
print(crosstab_result)
44-6-3、结果输出
# 44、pandas.crosstab函数
# 原始数据集:
#         Date         City Category  Values
# 0 2023-01-01     New York        A   100.0
# 1 2023-01-02  Los Angeles        A   200.0
# 2 2023-01-03     New York        B   150.0
# 3 2023-01-04  Los Angeles        B   250.0
# 4 2023-01-05     New York        A     NaN
# 5 2023-01-06  Los Angeles        B   300.0# crosstab结果:
# Category                             A      B     All
# Date                City                             
# 2023-01-01 00:00:00 New York     100.0    NaN   100.0
# 2023-01-02 00:00:00 Los Angeles  200.0    NaN   200.0
# 2023-01-03 00:00:00 New York       NaN  150.0   150.0
# 2023-01-04 00:00:00 Los Angeles    NaN  250.0   250.0
# 2023-01-05 00:00:00 New York       0.0    NaN     NaN
# 2023-01-06 00:00:00 Los Angeles    NaN  300.0   300.0
# All                              300.0  700.0  1000.0
45、pandas.cut函数
45-1、语法
# 45、pandas.cut函数
pandas.cut(x, bins, right=True, labels=None, retbins=False, precision=3, include_lowest=False, duplicates='raise', ordered=True)
Bin values into discrete intervals.Use cut when you need to segment and sort data values into bins. This function is also useful for going from a continuous variable to a categorical variable. For example, cut could convert ages to groups of age ranges. Supports binning into an equal number of bins, or a pre-specified array of bins.Parameters:
x
array-like
The input array to be binned. Must be 1-dimensional.bins
int, sequence of scalars, or IntervalIndex
The criteria to bin by.int : Defines the number of equal-width bins in the range of x. The range of x is extended by .1% on each side to include the minimum and maximum values of x.sequence of scalars : Defines the bin edges allowing for non-uniform width. No extension of the range of x is done.IntervalIndex : Defines the exact bins to be used. Note that IntervalIndex for bins must be non-overlapping.right
bool, default True
Indicates whether bins includes the rightmost edge or not. If right == True (the default), then the bins [1, 2, 3, 4] indicate (1,2], (2,3], (3,4]. This argument is ignored when bins is an IntervalIndex.labels
array or False, default None
Specifies the labels for the returned bins. Must be the same length as the resulting bins. If False, returns only integer indicators of the bins. This affects the type of the output container (see below). This argument is ignored when bins is an IntervalIndex. If True, raises an error. When ordered=False, labels must be provided.retbins
bool, default False
Whether to return the bins or not. Useful when bins is provided as a scalar.precision
int, default 3
The precision at which to store and display the bins labels.include_lowest
bool, default False
Whether the first interval should be left-inclusive or not.duplicates
{default ‘raise’, ‘drop’}, optional
If bin edges are not unique, raise ValueError or drop non-uniques.ordered
bool, default True
Whether the labels are ordered or not. Applies to returned types Categorical and Series (with Categorical dtype). If True, the resulting categorical will be ordered. If False, the resulting categorical will be unordered (labels must be provided).Returns:
out
Categorical, Series, or ndarray
An array-like object representing the respective bin for each value of x. The type depends on the value of labels.None (default) : returns a Series for Series x or a Categorical for all other inputs. The values stored within are Interval dtype.sequence of scalars : returns a Series for Series x or a Categorical for all other inputs. The values stored within are whatever the type in the sequence is.False : returns an ndarray of integers.bins
numpy.ndarray or IntervalIndex.
The computed or specified bins. Only returned when retbins=True. For scalar or sequence bins, this is an ndarray with the computed bins. If set duplicates=drop, bins will drop non-unique bin. For an IntervalIndex bins, this is equal to bins.
45-2、参数

45-2-1、x(必须)输入的数组或序列,包含要分组的连续数据。

45-2-2、bins(必须)区间边界的数组或序列,如果bins是一个整数,函数会自动生成从x.min()到x.max()的等宽区间,区间数量为bins(注意,这会导致bins-1个区间);如果bins是一个序列,它将被解释为区间的边界,并定义每个区间的开放或闭合。

45-2-3、right(可选,默认值为True)布尔值,如果为True,则区间是右闭的(即每个区间包括右端点);如果为False,则区间是左闭的(即每个区间包括左端点)。

45-2-4、labels(可选,默认值为None)用于标记输出类别的数组或序列,如果给定,它必须与生成的区间数量相同;如果未提供,则使用默认标签,如[(0, 1], (1, 2], ...。

45-2-5、retbins(可选,默认值为False)布尔值,如果为True,则返回区间边界数组和分类数组。

45-2-6、precision(可选,默认值为3)整数,用于设置返回区间标签的浮点数精度。只有当bins是整数且labels未指定时,此参数才有效。

45-2-7、include_lowest(可选,默认值为False)布尔值,如果为True,则第一个区间将包括其左边界,这对于不均匀的bins或当bins的第一个值大于x的最小值时特别有用。

45-2-8、duplicates(可选,默认值为'raise'){'raise', 'drop'},如果bins包含重复值,则:

45-2-8-1、'raise':引发ValueError。
45-2-8-2、'drop':删除重复值,但仅保留第一个出现的值。

45-2-9、ordered(可选,默认值为True)布尔值,如果为True,则返回的Categorical对象是有序的,这对于后续的数据分析(如排序)很重要。

45-3、功能

        将连续的数值型数据按照指定的区间(或称为“桶”)进行分割,从而将连续的数值变量转换为离散的类别变量,这在数据分析和机器学习的特征工程中尤其有用,因为它可以帮助揭示不同区间内的数据分布特征,或者简化模型的输入。

45-4、返回值

45-4-1、当不设置retbins=True时,pandas.cut函数返回一个Categorical对象,该对象包含了输入数据 x 中每个值所属的区间标签,Categorical对象是一种特殊的pandas数据类型,用于表示固定数量的类别,且这些类别是有序的(如果ordered=True)。

45-4-2、当设置retbins=True时,pandas.cut函数除了返回上述的Categorical对象外,还会额外返回一个数组,该数组包含了用于划分区间的边界值,这允许用户同时获取区间标签和区间边界,便于后续的数据处理和分析。

45-5、说明

        无

45-6、用法
45-6-1、数据准备
45-6-2、代码示例
# 45、pandas.cut函数
import pandas as pd
# 创建一个示例数据集
data = {'Age': [22, 25, 45, 33, 50, 41, 23, 37, 29, 31, 35, 48, 52, 44, 27]
}
df = pd.DataFrame(data)
print("原始数据集:")
print(df)
# 定义区间
bins = [20, 30, 40, 50, 60]
# 使用cut函数将年龄分割成不同的区间
df['Age Group'] = pd.cut(x=df['Age'],bins=bins,right=True,labels=['20-30', '30-40', '40-50', '50-60'],retbins=False,precision=0,include_lowest=True,duplicates='raise',ordered=True
)
print("\n分割后的数据集:")
print(df)
45-6-3、结果输出 
# 45、pandas.cut函数
# 原始数据集:
#     Age
# 0    22
# 1    25
# 2    45
# 3    33
# 4    50
# 5    41
# 6    23
# 7    37
# 8    29
# 9    31
# 10   35
# 11   48
# 12   52
# 13   44
# 14   27# 分割后的数据集:
#     Age Age Group
# 0    22     20-30
# 1    25     20-30
# 2    45     40-50
# 3    33     30-40
# 4    50     40-50
# 5    41     40-50
# 6    23     20-30
# 7    37     30-40
# 8    29     20-30
# 9    31     30-40
# 10   35     30-40
# 11   48     40-50
# 12   52     50-60
# 13   44     40-50
# 14   27     20-30
46、pandas.qcut函数
46-1、语法
# 46、pandas.qcut函数
pandas.qcut(x, q, labels=None, retbins=False, precision=3, duplicates='raise')
Quantile-based discretization function.Discretize variable into equal-sized buckets based on rank or based on sample quantiles. For example 1000 values for 10 quantiles would produce a Categorical object indicating quantile membership for each data point.Parameters:
x
1d ndarray or Series
q
int or list-like of float
Number of quantiles. 10 for deciles, 4 for quartiles, etc. Alternately array of quantiles, e.g. [0, .25, .5, .75, 1.] for quartiles.labels
array or False, default None
Used as labels for the resulting bins. Must be of the same length as the resulting bins. If False, return only integer indicators of the bins. If True, raises an error.retbins
bool, optional
Whether to return the (bins, labels) or not. Can be useful if bins is given as a scalar.precision
int, optional
The precision at which to store and display the bins labels.duplicates
{default ‘raise’, ‘drop’}, optional
If bin edges are not unique, raise ValueError or drop non-uniques.Returns:
out
Categorical or Series or array of integers if labels is False
The return type (Categorical or Series) depends on the input: a Series of type category if input is a Series else Categorical. Bins are represented as categories when categorical data is returned.bins
ndarray of floats
Returned only if retbins is True.NotesOut of bounds values will be NA in the resulting Categorical object
46-2、参数

46-2-1、x(必须)要分箱(或分桶)的一维数组或类似数组的对象。

46-2-2、q(必须)int或array-like of quantiles,如果是一个整数,它表示要分成的箱(或桶)的数量;如果是一个数组,则必须包含从0到1的浮点数,表示分位数。例如[0, 0.25, 0.5, 0.75, 1.]会将数据分成四个等宽的区间(或尽量等宽)。

46-2-3、labels(可选,默认值为None)用于指定每个箱(或桶)的标签,如果为None(默认值),则会自动生成标签(通常是基于整数索引的);如果为False,则不返回标签;如果提供了数组,其长度必须与生成的箱数相同。

46-2-4、retbins(可选,默认值为False)如果为True,则返回用于分箱的边界数组(即每个箱的最小值和下一个箱的最小值之间的值,除了最后一个箱,其边界是无穷大)。

46-2-5、precision(可选,默认值为3)控制内部计算的精度,更高的精度可以减少由浮点数舍入引起的误差,但可能会增加计算时间。

46-2-6、duplicates(可选,默认值为'raise')如果q参数中有重复的分位数,并且duplicates='raise'(默认值),则会抛出错误;如果duplicates='drop',则忽略重复的分位数。

46-3、功能

        用于将连续数据根据分位数划分成等频(或近似等频)区间的重要工具,其功能和返回值可以归纳如下:

46-3-1、等频分箱:pandas.qcut函数基于数据的分位数进行分箱,确保每个箱(或桶)中的样本数量大致相等(在可能的情况下),这对于需要平衡各个类别中样本数量的场景特别有用。

46-3-2、自定义分位数:除了将数据等频分箱外,用户还可以通过指定q参数中的分位数数组来自定义分箱方式,从而实现更精细的数据划分。

46-3-3、数据离散化:在数据预处理和特征工程中,pandas.qcut函数常用于将连续变量离散化,以便进行后续的分析、建模或可视化。

46-4、返回值

46-4-1、如果retbins=False(默认值),则返回两个对象:

46-4-1-1、bins:一个与x形状相同的分类数组(Categorical dtype),表示每个元素所属的箱(或桶)。

46-4-1-2、labels(如果指定了)一个数组,包含每个箱(或桶)的标签。

46-4-2、如果retbins=True,则返回三个对象:

46-4-2-1、bins :x形状相同的分类数组。

46-4-2-2、labels(如果指定了)一个数组,包含每个箱(或桶)的标签。

46-4-2-3、bin_edges:一个数组,表示箱(或桶)的边界。

46-5、说明

        无

46-6、用法
46-6-1、数据准备
46-6-2、代码示例
# 46、pandas.qcut函数
import pandas as pd
# 创建一个示例数据集
data = {'Age': [22, 25, 45, 33, 50, 41, 23, 37, 29, 31, 35, 48, 52, 44, 27]
}
df = pd.DataFrame(data)
print("原始数据集:")
print(df)
# 使用qcut函数将年龄按分位数分割成四个区间
df['Age Group'] = pd.qcut(x=df['Age'],q=4,labels=['Q1', 'Q2', 'Q3', 'Q4'],retbins=False,precision=3,duplicates='raise'
)
print("\n按分位数分割后的数据集:")
print(df)
46-6-3、结果输出
# 46、pandas.qcut函数
# 原始数据集:
#     Age
# 0    22
# 1    25
# 2    45
# 3    33
# 4    50
# 5    41
# 6    23
# 7    37
# 8    29
# 9    31
# 10   35
# 11   48
# 12   52
# 13   44
# 14   27# 按分位数分割后的数据集:
#     Age Age Group
# 0    22        Q1
# 1    25        Q1
# 2    45        Q4
# 3    33        Q2
# 4    50        Q4
# 5    41        Q3
# 6    23        Q1
# 7    37        Q3
# 8    29        Q2
# 9    31        Q2
# 10   35        Q2
# 11   48        Q4
# 12   52        Q4
# 13   44        Q3
# 14   27        Q1

二、推荐阅读

1、Python筑基之旅
2、Python函数之旅
3、Python算法之旅
4、Python魔法之旅
5、博客个人主页

相关文章:

Python酷库之旅-第三方库Pandas(018)

目录 一、用法精讲 44、pandas.crosstab函数 44-1、语法 44-2、参数 44-3、功能 44-4、返回值 44-5、说明 44-6、用法 44-6-1、数据准备 44-6-2、代码示例 44-6-3、结果输出 45、pandas.cut函数 45-1、语法 45-2、参数 45-3、功能 45-4、返回值 45-5、说明 4…...

九科bit-Worker RPA 内容学习

入门阶段, 花时间学习和记忆细枝末节,可能会反而分散新手去理解核心逻辑的精力,并且不常用的知识也很容易被遗忘。 简介: 什么是RPA? RPA(Robotic Process Automation,机器人流程自动化&#x…...

vscode编译环境配置-golang

1. 支持跳转 如果单测函数上方不显示run test | debug test,需要安装Code Debugger(因为以前的go Test Explorer不再被维护了) 2. 单测 指定单个用例测试 go test -v run TestXXXdlv 调试 需要安装匹配的go版本和delve版本(如…...

【JavaEE】网络编程——UDP

🤡🤡🤡个人主页🤡🤡🤡 🤡🤡🤡JavaEE专栏🤡🤡🤡 文章目录 1.数据报套接字(UDP)1.1特点1.2编码1.2.1DatagramSocket1.2.2DatagramPacket…...

JAVA毕业设计147—基于Java+Springboot的手机维修管理系统(源代码+数据库)

基于JavaSpringboot的手机维修管理系统(源代码数据库)147 一、系统介绍 本项目分为用户、管理员、维修员三种角色 1、用户: 注册、登录、新闻公告、售后申请、申请列表、意见反馈、个人信息、密码修改 2、管理员: 用户管理、用户管理、栏目管理、网…...

力扣第228题“汇总区间”

在本篇文章中,我们将详细解读力扣第228题“汇总区间”。通过学习本篇文章,读者将掌握如何遍历和汇总区间,并了解相关的复杂度分析和模拟面试问答。每种方法都将配以详细的解释,以便于理解。 问题描述 力扣第228题“汇总区间”描…...

部署大语言模型并对话

在阿里云的https://developer.aliyun.com/adc/scenario/b105013328814fe995c0f091d708d67d 选择函数计算 设置服务器配置 复制公网地址 这个地址不能直接 在返回应用,创建应用LLM 对话页面 Open WebUI 点击下面的创建应用 部署完成后访问域名 打开访问地址...

WebSocket、socket.io-client

WebSocket WebSocket 是一种网络通信协议,它提供了一个在单个长期持久的 TCP 连接上进行全双工(full-duplex)通信的通道。 WebSocket 允许客户端和服务器之间进行双向的数据交换,这意味着服务器可以主动向客户端推送数据&#x…...

Maven 仓库

在 Maven 世界中,任何一个依赖、插件或者项目构建的输出,都可以称为 构件 。 坐标和依赖是构件在 Maven 世界中的逻辑表示方式,构件的物理表示方式是文件,Maven 通过仓库来统一管理这些文件。 任何一个构件都有一组坐标唯一标识。…...

给后台写了一个优雅的自定义风格的数据日志上报页面

highlight: atelier-cave-dark 查看后台数据日志是非常常见的场景,经常看到后台的小伙伴从服务器日志复制一段json数据字符串,然后找一个JSON工具网页打开,在线JSON格式化校验。有的时候,一些业务需要展示mqtt或者socket的实时信息展示,如果不做任何修改直接展示一串字符…...

【React Native优质开源项目】

🌈个人主页: 程序员不想敲代码啊 🏆CSDN优质创作者,CSDN实力新星,CSDN博客专家 👍点赞⭐评论⭐收藏 🤝希望本文对您有所裨益,如有不足之处,欢迎在评论区提出指正,让我们共…...

Android 自动更新时间的数字时钟 TextClock

TextClock 继承 TextView &#xff0c;使用方法和 TextView 一样。 它专门用于显示数字时钟&#xff0c;可以自定义显示格式。 只要在布局文件里添加&#xff0c;它会自动更新时间&#xff0c;不需要添加刷新逻辑。 布局文件&#xff0c; <?xml version"1.0"…...

【Linux Git入门】Git的介绍

文章目录 前言git简介git是什么git的作用为什么要学习git安装git总结前言 在现代软件开发中,版本控制系统已经成为了不可或缺的工具。其中,Git是最受欢迎的版本控制系统之一。Git是由Linux的创造者Linus Torvalds在2005年创建的,用于管理Linux内核的开发。Git是一个分布式版…...

kafka面试题(基础-进阶-高阶)

目录 Kafka 基础篇 1.Kafka 的用途有哪些?使用场景如何? 2.Kafka 中的ISR、AR 又代表什么?ISR 的伸缩又指什么 3.Kafka 中的 HW、LEO、LSO、LW 等分别代表什么? 4.Kafka 中是怎么体现消息顺序性的? 5.Kafka 中的分区器、序列化器、拦截器是否了解?它们之间的处理顺序…...

《系统架构设计师教程(第2版)》第11章-未来信息综合技术-07-大数据技术概述

文章目录 1. 大数据的定义2. 大数据的研究内容2.1 面临的问题2.2 面临的挑战2.3 分析步骤2.3.1 数据获取和记录2.3.2 信息抽取和清洗2.3.3 数据集成、聚集和表示2.3.4 查询处理、数据建模和分析2.3.5 解释 3.大数据的应用领域3.1 制造业的应用3.2 服务业的应用3.3 交通行业的应…...

前端面试题54(断点续传讲解)

断点续传是一种在上传或下载大文件时&#xff0c;如果因为网络问题中断&#xff0c;可以从已经上传或下载的部分继续&#xff0c;而不是重新开始的技术。这对于提高用户体验和节省带宽非常有帮助。下面我将分别从HTTP协议层面、前端实现思路以及一个简单的前端实现示例来讲解断…...

YOLOv10改进 | Conv篇 | RCS-OSA替换C2f实现暴力涨点(减少通道的空间对象注意力机制)

一、本文介绍 本文给大家带来的改进机制是RCS-YOLO提出的RCS-OSA模块&#xff0c;其全称是"Reduced Channel Spatial Object Attention"&#xff0c;意即"减少通道的空间对象注意力"。这个模块的主要功能是通过减少特征图的通道数量&#xff0c;同时关注空…...

【C++BFS】690. 员工的重要性

本文涉及知识点 CBFS算法 LeetCode690. 员工的重要性 你有一个保存员工信息的数据结构&#xff0c;它包含了员工唯一的 id &#xff0c;重要度和直系下属的 id 。 给定一个员工数组 employees&#xff0c;其中&#xff1a; employees[i].id 是第 i 个员工的 ID。 employees[…...

视频调整帧率、分辨率+音画同步

# python data_utils/pre_video/multi_fps_crop_sync.pyimport cv2 import os from tqdm import tqdm import subprocess# 加载人脸检测模型 face_cascade cv2.CascadeClassifier(cv2.data.haarcascades haarcascade_frontalface_default.xml)def contains_face(frame):gray …...

【深度学习】关于模型加速

模型转为半精度的会加快推理速度吗 将模型转为半精度&#xff08;通常指16位浮点数&#xff0c;即FP16&#xff09;确实可以加快推理速度&#xff0c;同时还能减少显存&#xff08;GPU内存&#xff09;的使用。以下是一些关键点&#xff1a; 加快推理速度的原因 减少计算量&a…...

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周&#xff0c;有很多同学在写期末Java web作业时&#xff0c;运行tomcat出现乱码问题&#xff0c;经过多次解决与研究&#xff0c;我做了如下整理&#xff1a; 原因&#xff1a; IDEA本身编码与tomcat的编码与Windows编码不同导致&#xff0c;Windows 系统控制台…...

OpenLayers 可视化之热力图

注&#xff1a;当前使用的是 ol 5.3.0 版本&#xff0c;天地图使用的key请到天地图官网申请&#xff0c;并替换为自己的key 热力图&#xff08;Heatmap&#xff09;又叫热点图&#xff0c;是一种通过特殊高亮显示事物密度分布、变化趋势的数据可视化技术。采用颜色的深浅来显示…...

解锁数据库简洁之道:FastAPI与SQLModel实战指南

在构建现代Web应用程序时&#xff0c;与数据库的交互无疑是核心环节。虽然传统的数据库操作方式&#xff08;如直接编写SQL语句与psycopg2交互&#xff09;赋予了我们精细的控制权&#xff0c;但在面对日益复杂的业务逻辑和快速迭代的需求时&#xff0c;这种方式的开发效率和可…...

深入理解JavaScript设计模式之单例模式

目录 什么是单例模式为什么需要单例模式常见应用场景包括 单例模式实现透明单例模式实现不透明单例模式用代理实现单例模式javaScript中的单例模式使用命名空间使用闭包封装私有变量 惰性单例通用的惰性单例 结语 什么是单例模式 单例模式&#xff08;Singleton Pattern&#…...

MODBUS TCP转CANopen 技术赋能高效协同作业

在现代工业自动化领域&#xff0c;MODBUS TCP和CANopen两种通讯协议因其稳定性和高效性被广泛应用于各种设备和系统中。而随着科技的不断进步&#xff0c;这两种通讯协议也正在被逐步融合&#xff0c;形成了一种新型的通讯方式——开疆智能MODBUS TCP转CANopen网关KJ-TCPC-CANP…...

MySQL 8.0 OCP 英文题库解析(十三)

Oracle 为庆祝 MySQL 30 周年&#xff0c;截止到 2025.07.31 之前。所有人均可以免费考取原价245美元的MySQL OCP 认证。 从今天开始&#xff0c;将英文题库免费公布出来&#xff0c;并进行解析&#xff0c;帮助大家在一个月之内轻松通过OCP认证。 本期公布试题111~120 试题1…...

CMake 从 GitHub 下载第三方库并使用

有时我们希望直接使用 GitHub 上的开源库,而不想手动下载、编译和安装。 可以利用 CMake 提供的 FetchContent 模块来实现自动下载、构建和链接第三方库。 FetchContent 命令官方文档✅ 示例代码 我们将以 fmt 这个流行的格式化库为例,演示如何: 使用 FetchContent 从 GitH…...

Mac下Android Studio扫描根目录卡死问题记录

环境信息 操作系统: macOS 15.5 (Apple M2芯片)Android Studio版本: Meerkat Feature Drop | 2024.3.2 Patch 1 (Build #AI-243.26053.27.2432.13536105, 2025年5月22日构建) 问题现象 在项目开发过程中&#xff0c;提示一个依赖外部头文件的cpp源文件需要同步&#xff0c;点…...

稳定币的深度剖析与展望

一、引言 在当今数字化浪潮席卷全球的时代&#xff0c;加密货币作为一种新兴的金融现象&#xff0c;正以前所未有的速度改变着我们对传统货币和金融体系的认知。然而&#xff0c;加密货币市场的高度波动性却成为了其广泛应用和普及的一大障碍。在这样的背景下&#xff0c;稳定…...

Xen Server服务器释放磁盘空间

disk.sh #!/bin/bashcd /run/sr-mount/e54f0646-ae11-0457-b64f-eba4673b824c # 全部虚拟机物理磁盘文件存储 a$(ls -l | awk {print $NF} | cut -d. -f1) # 使用中的虚拟机物理磁盘文件 b$(xe vm-disk-list --multiple | grep uuid | awk {print $NF})printf "%s\n"…...