avatar
Articles
20
Tags
30
Categories
5

Home
Categories
About
技术杂货铺
Home
Categories
About

技术杂货铺

Cython浅出:最常用知识点都在这儿了
Created2023-09-17|Python
众所周知,Python是一门“极慢”的语言,无奈它写起来真的很快,各种库用起来太顺手了,以至于形成了良性的生态循环。这也导致越来越多的人用起了Python(主要是有很多代码可以抄啊…)。 但是在某些领域,对代码运行效率的要求还是挺高的,比如本人所在的优化算法领域。那我又想拥有Python的快速开发能力,又想获得较高的运行时效率,这怎么办? 有很多的加速方案,比如pybind11、numba、Cython等,个人一番体验下来觉得最简单的就是Cython啦,绝对是可以以最低成本获得不错效果的加速手段(之一?)。 这篇文章就简单介绍下Cython的一些核心用法,我也录了相关的系列视频在B站,建议关注我的B站Cython系列,其中包含完整的代码示例。 首先,Cython是什么?Cython 是一个功能强大的工具,它允许你以 Python 语言为基础编写代码,并通过一些优化技巧将其转化为 C 代码,从而提高运行时效率。文章标题只有浅出,没有深入,因为我自以为并没有很深入了解Cython,只是希望介绍一些 Cython 的核心用法,帮大家以最低成本(相对小的代码修改)获得不错的加速效果,具体包 ...
vim最常用命令
Created2023-08-25|Linux
Vim中的最常用命令 本指南系统地介绍了Vim中的修改、移动、搜索、多窗口等功能的使用方法, 整合了数10个示例,旨在帮助Vim初学者快速掌握必备的Vim编辑命令。 本文提供了一份较全的常用命令查询手册,如果希望根据使用频率来学习,可来我的B站频道 观看视频教程:Vim最常用命令指南。 文章结构如下: 一、修改命令(基础) 二、移动命令(基础) 三、组合编辑命令(用得贼多) 四、搜索和定位命令 五、多窗口命令 六、Visual模式 七、文件操作命令 每类命令都以示例讲解使用场景,力求深入浅出,可以作为Vim新手的实践指南,帮助各位快速上手Vim。 一、编辑命令(基础) 1. 插入(i) 在当前光标位置的字符之前进行插入。 使用方法:快捷键i 例如: 123456操作前: abc^操作:i test操作后:testabc 其中,^表示当前光标位置,后续示例中也会使用该符号表示光标位置。 2. 追加(a) 在当前光标位置的字符之后进行插入。 使用方法:快捷键a 例如: 123456操作前:abc^操作:a ba操作后: ababc 3. 替换(s) 删除当前光标位置的字符,并进入插入模 ...
一文搞懂Python排序:sorted() vs list.sort()
Created2023-07-23|Python
Python排序详解:sorted() vs list.sort() 在Python中排序数据时,我们通常会使用sorted()和list.sort()这两个函数。它们存在一些关键的区别,适用于不同的场景。本文将通过详细的示例阐述两者的差异,以及何时使用哪个函数更加合适。 list.sort() 的特点 list.sort()是列表对象的一个方法,作用是就地(in-place)对列表进行排序。也就是说,它直接修改了原列表,没有返回值: 123nums = [3, 1, 2]nums.sort() print(nums) # [1, 2, 3] list.sort()支持一些可选参数来自定义排序: reverse=True 倒序排序 key 根据自定义函数结果排序 例如: 1234567nums = [3,-2,1]nums.sort(reverse=True)print(nums) # [3, 1, -2] 倒序nums.sort(key=abs)print(nums) # [1,-2, 3] 根据绝对值排序 list.sort()只能用于列表,不能用于其他可迭代对象。它通过下 ...
深入浅出Python生成器
Created2023-07-22|Python
Understanding Python Generators and Efficient Sequences Introduction Python’s generators are a powerful feature that allows developers to create memory-efficient and lazy-evaluated sequences. Unlike regular sequences, such as lists, generators produce values on-the-fly, making them ideal for processing large datasets or infinite sequences. In this article, we will explore the concept of generators in Python, how to create them using generator functions and comprehensions, and understand their be ...
Linux/Unix常用命令: grep
Created2023-05-16|Linux
grep是Linux/Unix系统中非常常用的命令,它用来在文本文件中查找指定的模式并输出文本行。 以下均以or-tools文件夹中的 Dependencies.txt文件为例,其内容如下: 1234567891011Protobuf=v21.12abseil-cpp=20230125.0Cbc=2.10.7Cgl=0.60.5Clp=1.17.7Clp=1.17.7Osi=0.108.7CoinUtils=2.11.6Eigen=3.4.0Re2=2021-11-01Scip=v803 以下是grep命令的常用用法: 0. 递归查找 1grep -r pattern directory 使用-r选项可以递归查找指定目录下所有文件,而不仅仅是当前目录。 例:我们在or-tools外层文件夹中执行以下命令: 1grep -r Clp=1.17.7 or-tools/ 即可找到Clp=1.17.7出现的两行。 接下来我们进入or-tools文件夹,直接对Dependencies.txt文件进行操作。 1. 简单模式匹配 1grep pattern file 这个最简单的用法,会在指 ...
Powering Up Your Code: Parallel Programming with three Python packages
Created2023-05-05|Python
Introduction Parallel computing is a crucial aspect of modern-day computing that enables programs to perform computations faster and more efficiently. Python has several libraries that allow developers to write parallel programs, including Joblib, Ray, and Multiprocessing. In this blog post, we will explore the usage of these libraries and how they can help write efficient parallel programs. Choice 1: Joblib Joblib is a Python library that allows for easy parallelization of CPU-bound tasks. It ...
MapStruct and Lombok not working together
Created2023-05-05|Java
Problem When attempting to learn mapstruct as a new tool, I discovered that it does not seamlessly integrate with lombok annotations such as @AllArgsConstructor, as it suggests that the constructor does not exist. However, once I manually create the constructor, everything operates as intended. Clearly, the lombok annotation is not functioning as expected. Cause The reason why it does not work is because Maven only uses the MapStruct processor and not the Lombok one. The annotationProcessorPath ...
pip包管理基本使用
Created2023-04-29|Python
1. 镜像加速 在我们使用pip进行Python包安装时,如果我们需要使用镜像站来加速下载和安装,可以执行以下命令: 1.1 临时使用 1pip install -i https://mirrors.sjtug.sjtu.edu.cn/pypi/web/simple some-package 需要注意的是,simple不能少,而且是https而不是http。 1.2 长期使用 如果我们希望将该镜像站设为默认的源地址,可以先升级pip到最新版本,然后执行以下命令: 12pip install pip -Upip config set global.index-url https://mirrors.sjtug.sjtu.edu.cn/pypi/web/simple 如果我们连接pip默认源的网络连接较差,也可以使用以下命令临时使用这个镜像站来升级pip: 1pip install -i https://mirrors.sjtug.sjtu.edu.cn/pypi/web/simple pip -U 2. 依赖导入和导出 在Python项目中,我们通常会使用多个第三方包,这些包可以通过pi ...
From C++ to Python: How to Use Pybind11 for Cross-Language Interoperability
Created2023-04-29|Python
Introduction Pybind11 is a lightweight header-only library that allows you to expose C++ functions and classes to Python. It simplifies the process of creating Python bindings for C++ code and allows seamless interoperability between C++ and Python. In this article, we will discuss how to use Pybind11 to use C++ functions and classes in Python with a runnable example code. Prerequisites To follow along with this article, you should have: Basic knowledge of C++ and Python Basic knowledge of Pyt ...
pulp不同求解器设置参数
Created2023-04-26|优化
Pulp provides an easy-to-use syntax and interface for formulating and solving LP problems, including support for a wide range of problem types and solvers. It is widely used in operations research, supply chain management, logistics, and other industries for making optimization decisions. 1234567891011121314151617181920212223from pulp import *# Use CBC solverprob.solve(PULP_CBC_CMD(msg=True, timeLimit=1, options=["startalg", " ...
12
avatar
技术杂货铺
Articles
20
Tags
30
Categories
5
Follow Me
Announcement
You can contact me via Email 3290701522@qq.com~
Recent Post
Cython浅出:最常用知识点都在这儿了2023-09-17
vim最常用命令2023-08-25
一文搞懂Python排序:sorted() vs list.sort()2023-07-23
深入浅出Python生成器2023-07-22
Linux/Unix常用命令: grep2023-05-16
Categories
  • Java1
  • Linux3
  • Python10
  • 中科大凸优化课程笔记5
  • 优化1
Tags
api shell pybind11 tmux cpp 爬虫 后端框架 maven parallel programming grep solver joblib built-ins linux pip ray python加速 mapstruct pulp python cython 凸优化 django vim mip sorting lombok java generator multiprocessing
Archives
  • September 20231
  • August 20231
  • July 20232
  • May 20233
  • April 20233
  • March 20231
  • December 20223
  • April 20226
Info
Article :
20
UV :
PV :
Last Push :
©2020 - 2023 By 技术杂货铺
Framework Hexo|Theme Butterfly