infinity python inf

关于python中对np.array数据进行元素操作的讨论(形参与实参)

最近发现了python中,如果将np.array(ndarray)类型的数据作为实参,传递给形参时,实参和形参会同时改变。 例如下面的代码: ``` import numpy as np num=np.array([[1,2],[3,4]]) def test(a): a[0,1] = 9 prin ......
元素 数据 python array np

【Python】数字取反(相反数)的几种方法

方法一:绝对值 if __name__ == "__main__": """run""" print("负数取反-绝对值:{}".format(abs(-28))) print("正数数取反-绝对值:{}".format(abs(32) * -1)) 结果: 方法二:numpy库 # coding: ......
相反数 数字 方法 Python

-7 % 2Python3输出为啥是1?

大家好,我是皮皮。 ### 一、前言 前几天在Python黄金群【莫生气】问了一个`Python`基础问题,一起来看看吧。 ![image.png](https://upload-images.jianshu.io/upload_images/26239789-119bc17bcea7ad10.pn ......
2Python3 2Python Python3 Python

【Python】异常

异常 def execpt_test(a, b): result = a / b return result def divide_numbers(a, b): try: execpt_test(a, b) except ZeroDivisionError: print("除数不能为零!") pri ......
Python

python 单例模式

# python 单例模式 单例模式是一种设计模式,目的是确保一个类只有一个实例,并提供一个全局访问点来获取该实例。 有些类只需要一个全局唯一的实例,例如数据库连接池、线程池、日志记录器等。使用单例模式可以确保这些类只有一个实例存在,从而避免了资源的浪费和不一致的状态。 单例模式通常包含以下几个要素 ......
模式 python

python教程 入门学习笔记 第2天 第一个python程序 代码规范 用默认的IDLE (Python GUI)编辑器编写

四、第一个python程序 1、用默认的IDLE (Python GUI)编辑器编写 2、在新建文件中写代码,在初始窗口中编译运行 3、写完后保存为以.py扩展名的文件 4、按F5键执行,在初始窗口观看运行结果 5、代码规范: 1)先保存再执行 2)一句代码单独占一行 3)语法中的符号,必须使用英文 ......
python 编辑器 代码 笔记 程序

python mysql 快速分割导出到CSV

import random,string,re,time,sys,hashlib,pymysql,requests connect = pymysql.connect(user = 'm', password = 'h', db = 'x', host = 'r', port = 3306, cha ......
python mysql CSV

【Python自动化】多线程BFS站点结构爬虫代码,支持中断恢复,带注释

```py from collections import deque from urllib.parse import urljoin, urlparse import requests from pyquery import PyQuery as pq import re from EpubCr ......
爬虫 线程 注释 结构 站点

python定义常量类,禁止修改类属性

class NoModifyMeta(type): def __setattr__(cls, key, value): raise AttributeError(f"Cannot modify class attribute '{key}'") class ConstDict(metaclass=N ......
常量 属性 python

掌握 Python RegEx:深入探讨模式匹配

动动发财的小手,点个赞吧! ## 什么是正则表达式? 正则表达式通常缩写为 regex,是处理文本的有效工具。本质上,它们由一系列建立搜索模式的字符组成。该模式可用于广泛的字符串操作,包括匹配模式、替换文本和分割字符串。 ## 历史 ![](https://img2023.cnblogs.com/b ......
模式 Python RegEx

python截取文本

def sclip(): with open("file.txt", "r") as file: lines = file.readlines() first_line = lines[0:2] last_10_lines = lines[5:] first_line.extend(last_10_ ......
文本 python

掌握Python最强大的机器学习库

[TOC] # UIE-X在医疗领域的实战 **PaddleNLP全新发布UIE-X 🧾,除已有纯文本抽取的全部功能外,新增文档抽取能力。** UIE-X延续UIE的思路,**基于跨模态布局增强预训练模型**[文心ERNIE-Layout](https://github.com/PaddlePad ......
机器 Python

Python生成30万条Excel 测试数据

使用Python生成30万条Excel 测试数据 from openpyxl import Workbook from concurrent.futures import ThreadPoolExecutor # 定义生成数据的函数 def generate_data(start, end, she ......
万条 数据 Python Excel

Python基础day54 Django2

配置文件的介绍、静态文件的配置、request对象请求方法、pycharm连接数据库、Django连接MySQL、Django中的ORM、ORM增删改查字段、ORM增删改查数据 ......
Django2 基础 Python Django day

python虚拟环境拷贝到另一台电脑

背景介绍: 建立了虚拟环境后,在其中安装的包很多,也很费时间,你想将这个MyApp放到其他电脑上去开发,是不是直接复制MyApp文件夹就可以了呢? 不行!因为在建立虚拟环境时,虚拟环境中的python.exe, pip.exe......等一些文件会“硬编码”,记录的是绝对路径,放到其他电脑后,因为 ......
拷贝 环境 python 电脑

python学习_列表

一、为什么需要列表 变量可以存储一个元素,而列表是一个"大容器",可以存储N多个元素,且元素可以是不同的类型,程序可以很方便的对这些数据进行整体操作 列表相当于其他语言中的数组 列表索引示意图: 二、列表的创建 列表使用中括号即可创建,列表中的不同元素之间使用英文的逗号进行分隔 上面列表的内存示意图 ......
python

Python面向对象编程-学习笔记

课程地址:https://www.bilibili.com/video/BV1qm4y1L7y1/ 1. Pass占位符,新建类后如果暂时不确定如何实现,可用pass占位 2.构造函数,属性 # Python Object-Oriented Programming class Employee: d ......
对象 笔记 Python

python 性能测试之获取app 电脑消耗

一、实现代码 import os,csv import time import numpy as np from matplotlib import pyplot as plt from check_package import check_package import math battery_l ......
性能 python 电脑 app

python @property的介绍与使用

python @property的介绍与使用 python的@property是python的一种装饰器,是用来修饰方法的。 作用: 我们可以使用@property装饰器来创建只读属性,@property装饰器会将方法转换为相同名称的只读属性,可以与所定义的属性配合使用,这样可以防止属性被修改。 使 ......
property python

python计算多站点多年标准化权重降水指数SPIW

目标计算的是SPIW60为近60天的标准化权重降水指数 1、先计算好WAP,上一个帖子已经算好 2、再计算SPI2(WAP) 代码如下: #!usr/bin/env python # -*- coding:utf-8 -*- """ @author: Su @file: getWAP.py @tim ......
降水 权重 多年 指数 站点

python之product迭代

前言:学习本篇之前,先了解一下和permutations()函数,combinations()函数三者之间的区别。 python——combinations()函数_xiaofengdada的博客-CSDN博客 python——permutations()函数_xiaofengdada的博客-CSD ......
product python

Python计算多站点多年权重累积降水量WAP

之前计算过单站点的WAP,现在计算多站点的WAP 数据样子直接参考上几次的文章 直接上代码: #!usr/bin/env python # -*- coding:utf-8 -*- """ @author: Su @file: getWAP.py @time: 2023/07/27 @desc: " ......
降水量 降水 权重 多年 站点

python 路径规范化,保持路径一致性normpath

os.path.normpath 是 Python 中 os 模块的一个方法,用于规范化路径。它接受一个路径字符串作为参数,并返回一个规范化的路径字符串。 具体来说,os.path.normpath 会将路径字符串进行以下操作: 去除多余的斜杠(/或\)。 将斜杠(/或\)转换为操作系统特定的分隔符 ......
路径 一致性 normpath python

python 分割字符

#输入王小明,输出王 小明 #读取原始txt文件 with open('D:\\PCCW_Test_Script\\111.txt', encoding='utf-8') as file1: content = file1.readlines() # print(content) with open ......
字符 python

python之assert

assert断言迷糊的一段代码: ``` assert (points_per_side is None) != ( point_grids is None ), "Exactly one of points_per_side or point_grid must be provided." ``` ......
python assert

python计算两个时间的时间差

from datetime import datetime # Define the start time and end time as strings start_time_str = "2023-07-20 10:30:00" # Replace with your start time st ......
时间 时间差 两个 python

Python @classmethod decorator and static method All In One

# Python @classmethod decorator and static method All In One > 修饰器/装饰器;静态方法;实例方法 ```py # cls class Rectangle: def __init__(self, width, height): self. ......
classmethod decorator Python static method

python使用ctypes调用gcc编译的dll之ctypes的使用

### 简介 ctypes 是 Python 的外部函数库。它提供了与 C 兼容的数据类型,并允许调用C或C++编译后的DLL 或共享库中的函数。可使用该模块以纯 Python 形式对这些库进行封装。 本例中代码基于window系统,python为64位3.9.12,如需在liunx上使用请参考[上 ......
ctypes python gcc dll

python使用多进程multiprocessing执行报错

in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be froze ......
multiprocessing 进程 python

python 日志

#coding:utf-8 import logging import sys import os import datetime from logging import handlers class Logger(object): def __init__(self,name): LOGGING_ ......
python 日志