NumPyreshape函数实现数组重塑

 更新时间:2026年10月31日 15:22:06   作者:知远漫谈  
本文深入讲解NumPy中reshape函数的核心原理与实践应用,详细讲解reshape的原理、-1参数、与resize的区别,具有一定的参考价值,感兴趣的可以了解一下

在数据科学和机器学习的世界中,NumPy 作为 Python 最重要的科学计算库之一,为我们提供了强大的多维数组操作功能。其中,reshape 函数是处理数组形状变换的核心工具之一。今天,我们将深入探讨这个强大函数的各种用法和应用场景。

🔍 什么是 reshape 函数?

reshape 函数允许我们在不改变数组数据的情况下重新组织数组的形状。换句话说,它可以帮助我们将一维数组转换为二维、三维或多维数组,或者进行相反的操作。

import numpy as np

# 创建一个一维数组
arr = np.array([1, 2, 3, 4, 5, 6])
print("原始数组:", arr)
print("原始形状:", arr.shape)

# 使用 reshape 将其转换为 2x3 的二维数组
reshaped_arr = arr.reshape(2, 3)
print("重塑后的数组:")
print(reshaped_arr)
print("新形状:", reshaped_arr.shape)

输出结果:

原始数组: [1 2 3 4 5 6]
原始形状: (6,)
重塑后的数组:
[[1 2 3]
 [4 5 6]]
新形状: (2, 3)

🧠 reshape 的核心原理

为了更好地理解 reshape 函数的工作原理,我们需要了解一些基本概念:

数据连续性

NumPy 中的数组在内存中是以连续的方式存储的。当我们使用 reshape 时,实际上只是改变了我们如何"看待"这些数据的方式,而不会移动或复制实际的数据。

形状兼容性

在进行 reshape 操作时,新旧形状的元素总数必须保持一致。例如,一个包含 12 个元素的一维数组可以被重塑为以下形状:

  • (12,) - 1行12列
  • (3, 4) - 3行4列
  • (2, 6) - 2行6列
  • (2, 2, 3) - 2层2行3列的三维数组

让我们通过代码来验证这一点:

# 创建一个包含12个元素的数组
original_array = np.arange(12)
print("原始数组:", original_array)
print("元素总数:", original_array.size)

# 尝试不同的重塑方式
shapes_to_try = [(3, 4), (2, 6), (4, 3), (2, 2, 3), (1, 12)]

for shape in shapes_to_try:
    try:
        reshaped = original_array.reshape(shape)
        print(f"成功重塑为 {shape}:")
        print(reshaped)
        print()
    except ValueError as e:
        print(f"无法重塑为 {shape}: {e}")
        print()

📊 基本 reshape 操作示例

一维到二维的转换

最常见的 reshape 应用就是将一维数组转换为二维数组:

# 创建一维数组
data = np.array([1, 2, 3, 4, 5, 6, 7, 8])

# 转换为 2x4 矩阵
matrix_2x4 = data.reshape(2, 4)
print("2x4 矩阵:")
print(matrix_2x4)

# 转换为 4x2 矩阵
matrix_4x2 = data.reshape(4, 2)
print("\n4x2 矩阵:")
print(matrix_4x2)

# 转换为 1x8 矩阵(行向量)
row_vector = data.reshape(1, 8)
print("\n行向量:")
print(row_vector)

# 转换为 8x1 矩阵(列向量)
column_vector = data.reshape(8, 1)
print("\n列向量:")
print(column_vector)

多维数组的重塑

reshape 不仅适用于一维到二维的转换,还可以处理更复杂的多维数组重塑:

# 创建一个三维数组
array_3d = np.arange(24).reshape(2, 3, 4)
print("原始三维数组:")
print(array_3d)
print("形状:", array_3d.shape)

# 重塑为二维数组
array_2d = array_3d.reshape(6, 4)
print("\n重塑为 6x4 二维数组:")
print(array_2d)

# 重塑为一维数组
array_1d = array_3d.reshape(-1)  # -1 表示自动计算该维度大小
print("\n重塑为一维数组:")
print(array_1d)

🔢 使用 -1 自动推断维度

在 reshape 中,我们可以使用 -1 来让 NumPy 自动计算某个维度的大小。这是一个非常实用的功能:

# 创建一个包含20个元素的数组
arr = np.arange(20)
print("原始数组:", arr)

# 让 NumPy 自动计算行数,指定列数为5
reshaped_auto_rows = arr.reshape(-1, 5)
print("\n自动计算行数 (列=5):")
print(reshaped_auto_rows)
print("形状:", reshaped_auto_rows.shape)

# 让 NumPy 自动计算列数,指定行数为4
reshaped_auto_cols = arr.reshape(4, -1)
print("\n自动计算列数 (行=4):")
print(reshaped_auto_cols)
print("形状:", reshaped_auto_cols.shape)

# 在三维数组中的应用
arr_3d = arr.reshape(2, -1, 5)
print("\n三维数组 (固定第一维=2, 第三维=5):")
print(arr_3d)
print("形状:", arr_3d.shape)

需要注意的是,在一次 reshape 操作中只能有一个维度使用 -1,否则 NumPy 无法确定确切的形状。

🔄 reshape vs resize

虽然 reshape 和 resize 都可以改变数组的形状,但它们有着本质的区别:

# 创建原始数组
original = np.array([1, 2, 3, 4, 5, 6])
print("原始数组:", original)

# 使用 reshape(要求元素总数不变)
try:
    reshaped = original.reshape(2, 3)
    print("reshape 结果:")
    print(reshaped)
except ValueError as e:
    print("reshape 错误:", e)

# 使用 resize(会修改原数组,并可能重复或截断元素)
resized_copy = np.resize(original, (2, 5))
print("\nresize 结果:")
print(resized_copy)

reshape 是一种视图操作,不会创建新的数据副本;而 resize 可能会创建新的数组并修改数据内容。

🎯 实际应用场景

数据预处理

在机器学习项目中,我们经常需要将一维特征向量重塑为特定的形状:

# 模拟一批图像数据(假设每张图片有784个像素点)
batch_size = 32
pixels_per_image = 784
image_data = np.random.rand(batch_size * pixels_per_image)

# 将扁平化的数据重塑为批次形式
images_batch = image_data.reshape(batch_size, pixels_per_image)
print(f"批量图像数据形状: {images_batch.shape}")

# 进一步重塑为具体的图像尺寸(28x28)
images_reshaped = images_batch.reshape(batch_size, 28, 28)
print(f"重塑后图像形状: {images_reshaped.shape}")

矩阵运算准备

在进行矩阵运算前,有时需要调整数组的形状以匹配运算要求:

# 创建两个向量
vector_a = np.array([1, 2, 3, 4])
vector_b = np.array([5, 6, 7, 8])

# 为了进行矩阵乘法,需要调整形状
a_column = vector_a.reshape(-1, 1)  # 转换为列向量
b_row = vector_b.reshape(1, -1)     # 转换为行向量

# 矩阵乘法
result = np.dot(a_column, b_row)
print("矩阵乘法结果:")
print(result)
print("结果形状:", result.shape)

📈 高级 reshape 技巧

使用 order 参数控制重塑顺序

NumPy 提供了 order 参数来控制重塑时元素的排列顺序:

# 创建测试数组
test_array = np.arange(12).reshape(3, 4)
print("原始数组:")
print(test_array)

# 展平为一维数组
flattened_c = test_array.reshape(-1, order='C')  # C风格(行优先)
flattened_f = test_array.reshape(-1, order='F')  # Fortran风格(列优先)

print("\nC风格展平:")
print(flattened_c)

print("\nFortran风格展平:")
print(flattened_f)

处理不规则重塑需求

有时候我们需要进行一些特殊的重塑操作:

# 创建一个较大的数组
large_array = np.arange(24).reshape(2, 3, 4)
print("原始三维数组:")
print(large_array)

# 将所有元素重新组织为多个较小的块
blocks = large_array.reshape(2, 3, 2, 2)
print("\n重塑为块结构:")
print(blocks)

# 或者重新组织为不同的维度组合
alternative = large_array.reshape(6, 4)
print("\n替代重塑方案:")
print(alternative)

🛠️ 性能考虑和最佳实践

内存效率

由于 reshape 返回的是原数组的视图而不是副本,因此它是内存高效的:

import sys

# 创建大数组
large_data = np.random.rand(1000, 1000)
print(f"原始数组内存占用: {sys.getsizeof(large_data)} 字节")

# reshape 操作
reshaped_view = large_data.reshape(-1)
print(f"重塑后视图内存占用: {sys.getsizeof(reshaped_view)} 字节")

# 注意:这只是视图的开销,实际数据没有复制

避免不必要的重塑

在编写代码时,我们应该避免不必要的重塑操作:

# 不推荐的做法:多次重塑
data = np.arange(100)
step1 = data.reshape(10, 10)
step2 = step1.reshape(-1)
final_result = step2.reshape(5, 20)

# 推荐的做法:直接重塑为目标形状
direct_result = data.reshape(5, 20)

# 两者结果相同,但后者更高效
print("两种方法结果是否相同:", np.array_equal(final_result, direct_result))

🧪 错误处理和调试技巧

在使用 reshape 时可能会遇到各种错误,了解如何处理这些情况很重要:

# 常见错误示例
test_array = np.arange(10)

# 错误1:元素总数不匹配
try:
    wrong_shape = test_array.reshape(3, 4)  # 3*4=12 != 10
except ValueError as e:
    print("❌ 元素总数不匹配错误:", e)

# 错误2:多个-1参数
try:
    multiple_neg_one = test_array.reshape(-1, -1)
except ValueError as e:
    print("❌ 多个-1参数错误:", e)

# 错误3:负数维度(除-1外)
try:
    negative_dim = test_array.reshape(-2, 5)
except ValueError as e:
    print("❌ 负数维度错误:", e)

# 正确的处理方式
def safe_reshape(arr, new_shape):
    """安全的重塑函数"""
    try:
        return arr.reshape(new_shape)
    except ValueError as e:
        print(f"重塑失败: {e}")
        print(f"原数组形状: {arr.shape}, 目标形状: {new_shape}")
        return None

# 测试安全函数
result1 = safe_reshape(test_array, (2, 5))  # 正确
result2 = safe_reshape(test_array, (3, 4))  # 错误

if result1 is not None:
    print("✅ 成功重塑:")
    print(result1)

📚 与其他 NumPy 函数的配合使用

与 flatten 和 ravel 的关系

# 创建测试数组
test_matrix = np.array([[1, 2, 3], [4, 5, 6]])
print("原始矩阵:")
print(test_matrix)

# 使用 reshape 展平
flattened_by_reshape = test_matrix.reshape(-1)
print("\n使用 reshape 展平:")
print(flattened_by_reshape)

# 使用 flatten 展平
flattened_by_flatten = test_matrix.flatten()
print("\n使用 flatten 展平:")
print(flattened_by_flatten)

# 使用 ravel 展平
flattened_by_ravel = test_matrix.ravel()
print("\n使用 ravel 展平:")
print(flattened_by_ravel)

# 区别:flatten 总是返回副本,ravel 尽可能返回视图
print("\n内存地址比较:")
print("reshape 视图:", flattened_by_reshape.base is test_matrix)
print("flatten 副本:", flattened_by_flatten.base is test_matrix)
print("ravel 视图:", flattened_by_ravel.base is test_matrix)

与 transpose 的结合使用

# 创建三维数组
array_3d = np.arange(24).reshape(2, 3, 4)
print("原始三维数组:")
print(array_3d)

# 先转置再重塑
transposed = array_3d.transpose(2, 1, 0)  # 改变轴的顺序
reshaped_after_transpose = transposed.reshape(4, 6)
print("\n转置后重塑:")
print(reshaped_after_transpose)

# 或者先重塑再转置
reshaped_first = array_3d.reshape(6, 4)
transposed_after_reshape = reshaped_first.T  # .T 是 transpose() 的简写
print("\n重塑后转置:")
print(transposed_after_reshape)

🎨 实际案例分析

让我们通过几个实际案例来展示 reshape 的强大功能:

案例1:图像数据处理

# 模拟彩色图像处理(RGB通道)
height, width, channels = 28, 28, 3
num_images = 100

# 创建模拟的图像数据集
image_dataset = np.random.randint(0, 256, (num_images, height, width, channels), dtype=np.uint8)
print(f"图像数据集形状: {image_dataset.shape}")

# 如果需要将图像展平用于某些算法
flattened_images = image_dataset.reshape(num_images, -1)
print(f"展平后的图像数据形状: {flattened_images.shape}")

# 如果需要单独处理每个颜色通道
separated_channels = image_dataset.reshape(num_images, height * width, channels)
print(f"分离通道后的形状: {separated_channels.shape}")

案例2:时间序列数据分析

# 模拟传感器数据
num_sensors = 5
time_steps = 1000

# 创建模拟的时间序列数据
sensor_data = np.random.randn(time_steps, num_sensors)
print(f"原始传感器数据形状: {sensor_data.shape}")

# 如果要将其重新组织为批次形式用于深度学习
batch_size = 32
sequence_length = 50

# 计算可以形成的完整批次数量
num_batches = time_steps // sequence_length
usable_time_steps = num_batches * sequence_length

# 重塑为批次序列
batched_sequences = sensor_data[:usable_time_steps].reshape(
    num_batches, sequence_length, num_sensors
)
print(f"批次化序列形状: {batched_sequences.shape}")

案例3:特征工程中的维度变换

# 模拟特征工程场景
samples = 1000
original_features = 120

# 创建特征矩阵
feature_matrix = np.random.randn(samples, original_features)
print(f"原始特征矩阵形状: {feature_matrix.shape}")

# 假设我们要将特征重新组织为网格形式
# 寻找合适的因数组合
def find_factor_pairs(n):
    factors = []
    for i in range(1, int(np.sqrt(n)) + 1):
        if n % i == 0:
            factors.append((i, n // i))
    return factors

factor_pairs = find_factor_pairs(original_features)
print(f"\n{original_features} 的因数组合:")
for pair in factor_pairs:
    print(f"  {pair[0]} x {pair[1]}")

# 选择一个合适的组合进行重塑
reshaped_features = feature_matrix.reshape(samples, 12, 10)
print(f"\n重塑后的特征形状: {reshaped_features.shape}")

# 这种形式可能更适合卷积神经网络等模型

📊 数据可视化预处理

在进行数据可视化之前,经常需要对数据进行重塑:

# 创建用于可视化的数据
x = np.linspace(0, 2*np.pi, 100)
y = np.linspace(0, 2*np.pi, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) * np.cos(Y)

print(f"X 网格形状: {X.shape}")
print(f"Y 网格形状: {Y.shape}")
print(f"Z 值形状: {Z.shape}")

# 如果需要将网格数据转换为散点图格式
points_x = X.reshape(-1)
points_y = Y.reshape(-1)
values_z = Z.reshape(-1)

print(f"\n重塑后的点坐标形状:")
print(f"X 坐标: {points_x.shape}")
print(f"Y 坐标: {points_y.shape}")
print(f"Z 值: {values_z.shape}")

# 这种格式适合用于 scatter plot 等可视化

🤖 机器学习中的应用

在机器学习领域,reshape 函数扮演着重要角色:

# 模拟机器学习数据预处理流程
class DataPreprocessor:
    def __init__(self):
        self.original_shape = None
        
    def prepare_for_training(self, data, target_shape=None):
        """为训练准备数据"""
        self.original_shape = data.shape
        
        if target_shape is None:
            # 默认情况下,如果是多维数据则展平
            if len(data.shape) > 1:
                return data.reshape(data.shape[0], -1)
            else:
                return data.reshape(-1, 1)
        else:
            return data.reshape(target_shape)
    
    def restore_original_shape(self, processed_data):
        """恢复原始形状"""
        if self.original_shape:
            return processed_data.reshape(self.original_shape)
        else:
            raise ValueError("没有保存原始形状信息")

# 使用示例
preprocessor = DataPreprocessor()

# 模拟不同类型的输入数据
image_data = np.random.rand(100, 28, 28)  # 图像数据
tabular_data = np.random.rand(100, 10)    # 表格数据
time_series = np.random.rand(1000,)      # 时间序列

# 处理不同类型的数据
processed_images = preprocessor.prepare_for_training(image_data)
processed_tabular = preprocessor.prepare_for_training(tabular_data)
processed_series = preprocessor.prepare_for_training(time_series, (-1, 1))

print("处理后的形状:")
print(f"图像数据: {processed_images.shape}")
print(f"表格数据: {processed_tabular.shape}")
print(f"时间序列: {processed_series.shape}")

📈 性能优化技巧

合理使用视图和副本

import time

# 创建大型数组进行性能测试
large_array = np.random.rand(10000, 1000)

# 测试 reshape(视图操作)的性能
start_time = time.time()
view_result = large_array.reshape(-1)
view_time = time.time() - start_time

# 测试 copy 操作的性能
start_time = time.time()
copy_result = large_array.copy().reshape(-1)
copy_time = time.time() - start_time

print(f"reshape 视图操作耗时: {view_time:.6f} 秒")
print(f"copy 后 reshape 耗时: {copy_time:.6f} 秒")
print(f"性能差异: {copy_time/view_time:.2f} 倍")

批量操作优化

# 对于大批量数据处理,合理的重塑策略很重要
def efficient_batch_reshape(data, batch_size, target_shape):
    """高效的批量重塑"""
    total_samples = data.shape[0]
    num_batches = total_samples // batch_size
    
    batches = []
    for i in range(num_batches):
        start_idx = i * batch_size
        end_idx = start_idx + batch_size
        batch = data[start_idx:end_idx].reshape(batch_size, *target_shape)
        batches.append(batch)
    
    return np.array(batches)

# 示例使用
sample_data = np.random.rand(1000, 784)  # 1000个样本,每个784维
batches = efficient_batch_reshape(sample_data, 32, (28, 28))
print(f"批量处理结果形状: {batches.shape}")

🧩 复杂重塑模式

分块重塑

def block_reshape(array, block_shape):
    """将数组分块重塑"""
    original_shape = array.shape
    new_shape = []
    
    for i, (orig_dim, block_dim) in enumerate(zip(original_shape, block_shape)):
        if orig_dim % block_dim != 0:
            raise ValueError(f"维度 {i} 不能被 {block_dim} 整除")
        new_shape.extend([orig_dim // block_dim, block_dim])
    
    return array.reshape(new_shape)

# 示例:将 6x6 矩阵重塑为 3x2x3x2 的块结构
matrix_6x6 = np.arange(36).reshape(6, 6)
print("原始矩阵:")
print(matrix_6x6)

block_structure = block_reshape(matrix_6x6, (3, 2))
print("\n块结构重塑:")
print(block_structure)
print("新形状:", block_structure.shape)

滑动窗口重塑

def sliding_window_reshape(array, window_size, step=1):
    """滑动窗口重塑"""
    if len(array.shape) != 1:
        raise ValueError("只支持一维数组")
    
    data_length = array.shape[0]
    num_windows = (data_length - window_size) // step + 1
    
    # 创建索引矩阵
    indices = np.arange(window_size)[None, :] + np.arange(num_windows)[:, None] * step
    return array[indices]

# 示例:创建滑动窗口
time_series = np.arange(20)
windowed_data = sliding_window_reshape(time_series, window_size=5, step=2)
print("时间序列:", time_series)
print("滑动窗口重塑结果:")
print(windowed_data)

📚 学习资源和进一步阅读

对于想要深入了解 NumPy 和数组操作的读者,我推荐以下资源:

🎯 最佳实践总结

通过以上详细的介绍和示例,我们可以总结出使用 reshape 函数的最佳实践:

  1. 理解数据布局:始终清楚你的数据是如何在内存中组织的
  2. 利用视图特性:尽可能使用 reshape 的视图特性来节省内存
  3. 合理使用 -1:善用自动推断维度功能简化代码
  4. 检查形状兼容性:确保重塑前后元素总数保持一致
  5. 注意性能影响:在大数据集上操作时要考虑性能因素
  6. 错误处理:为可能的 reshape 错误做好异常处理
# 综合示例:完整的 reshape 工具类
class ReshapeToolkit:
    @staticmethod
    def safe_reshape(array, new_shape):
        """安全重塑函数"""
        try:
            return array.reshape(new_shape)
        except ValueError as e:
            print(f"重塑失败: {e}")
            return None
    
    @staticmethod
    def find_compatible_shapes(total_elements, max_dimensions=3):
        """查找兼容的形状组合"""
        import math
        
        shapes = []
        # 查找所有可能的因数组合
        for i in range(1, int(math.sqrt(total_elements)) + 1):
            if total_elements % i == 0:
                j = total_elements // i
                shapes.append((i, j))
                
                # 如果允许多个维度,继续分解
                if max_dimensions > 2:
                    for k in range(1, int(math.sqrt(j)) + 1):
                        if j % k == 0:
                            l = j // k
                            shapes.append((i, k, l))
        
        return shapes
    
    @staticmethod
    def batch_reshape(data, batch_size):
        """批量重塑"""
        total_samples = data.shape[0]
        usable_samples = (total_samples // batch_size) * batch_size
        return data[:usable_samples].reshape(-1, batch_size, *data.shape[1:])

# 使用工具类
toolkit = ReshapeToolkit()

# 测试数据
test_data = np.arange(60)
print("测试数据形状:", test_data.shape)

# 查找兼容形状
compatible_shapes = toolkit.find_compatible_shapes(60, max_dimensions=3)
print("\n兼容的形状组合:")
for shape in compatible_shapes[:10]:  # 显示前10个
    print(f"  {shape}")

# 安全重塑
result = toolkit.safe_reshape(test_data, (6, 10))
if result is not None:
    print("\n安全重塑成功:")
    print(result.shape)

🌟 结语

reshape 函数是 NumPy 中最强大和最有用的工具之一。通过本文的学习,你应该已经掌握了:

  • reshape 的基本语法和用法
  • 如何使用 -1 参数进行智能维度推断
  • 不同重塑场景下的最佳实践
  • 与其他 NumPy 函数的协同使用
  • 性能优化和错误处理技巧

记住,掌握 reshape 不仅是为了完成特定的任务,更是为了培养对多维数据结构的深刻理解。这种理解将在你进行数据分析、机器学习和科学计算时发挥重要作用。

随着你在数据科学领域的不断深入,你会发现 reshape 函数的应用场景远比本文介绍的更加丰富和多样。关键是要保持好奇心,勇于尝试不同的重塑策略,并在实践中不断完善自己的技能。

到此这篇关于NumPyreshape函数实现数组重塑的文章就介绍到这了,更多相关NumPy reshape数组重塑 内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Python第三方库face_recognition在windows上的安装过程

    Python第三方库face_recognition在windows上的安装过程

    今天为大家介绍下face recognition在Windows系统上安装与使用,但在Windows平台上face recognition性能会有所下降
    2019-05-05
  • Python实现导弹自动追踪代码实例

    Python实现导弹自动追踪代码实例

    这篇文章主要介绍了Python实现导弹自动追踪代码实例,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-11-11
  • Python制作微信好友背景墙教程(附完整代码)

    Python制作微信好友背景墙教程(附完整代码)

    这篇文章主要介绍了Python制作微信好友背景墙教程(附完整代码),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-07-07
  • 如何使用python读取Excel指定范围并转为数组

    如何使用python读取Excel指定范围并转为数组

    python处理数据文件的途径有很多种,下面这篇文章主要给大家介绍了关于如何使用python读取Excel指定范围并转为数组的相关资料,文中通过图文以及实例代码介绍的非常详细,需要的朋友可以参考下
    2022-11-11
  • 使用Python做垃圾分类的原理及实例代码附源码

    使用Python做垃圾分类的原理及实例代码附源码

    这篇文章主要介绍了用Python做垃圾分类的实现原理,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值 ,需要的朋友可以参考下
    2019-07-07
  • 关于Kotlin中SAM转换的那些事

    关于Kotlin中SAM转换的那些事

    这篇文章主要给大家介绍了关于Kotlin中SAM转换的那些事,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-09-09
  • Python3实现发送QQ邮件功能(附件)

    Python3实现发送QQ邮件功能(附件)

    这篇文章主要为大家详细介绍了Python3实现发送QQ邮件功能,附件方面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-12-12
  • python如何利用cv2.rectangle()绘制矩形框

    python如何利用cv2.rectangle()绘制矩形框

    cv2.rectangle这个函数的作用是在图像上绘制一个简单的矩形,下面这篇文章主要给大家介绍了关于python如何利用cv2.rectangle()绘制矩形框的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下
    2022-12-12
  • python 常用日期处理-- datetime 模块的使用

    python 常用日期处理-- datetime 模块的使用

    这篇文章主要介绍了python 如何对日期进行处理,帮助大家更好的理解和学习python,感兴趣的朋友可以了解下
    2020-09-09
  • Pycharm的虚拟环境设置过程

    Pycharm的虚拟环境设置过程

    该文章记录了在PyCharm中设置虚拟环境并更新pip及安装pandas包的过程,显示所有依赖包均已满足最新版本要求,无需更新安装
    2026-05-05

最新评论