python的杂七杂八

 Python Programming and Numerical Methods - A Guide for Engineers and Scientistsicon-default.png?t=N7T8https://www.elsevier.com/books/python-programming-and-numerical-methods/kong/978-0-12-819549-9,

某乎上推荐的剑桥大学出版社出版的numerical methods in engineering with python

说是讲了数值代数、曲线拟合、方程求根、数值微分方程和一点点的最优化,很基础,适合攻城狮。

Chapter 1. Python Basics

1.1 Getting Started with Python

首先要配置一个编程的环境。

Set up working environment。推荐使用 Anaconda or Miniconda 来install和manage软件包。

  1. conda是一个包和环境管理工具,它不仅能管理包,还能隔离和管理不同python版本的环境。类似管理nodejs环境的nvm工具。
  2. anaconda和miniconda都是conda的一种发行版。只是包含的包不同。
  3. anaconda包含了conda、python等180多个科学包及其依赖项,体格比较大。但很多东西你未必用到,所以才有mini版。
  4. miniconda是最小的conda安装环境,只有conda+python+pip+zlib和一些其他常用的包,体格非常迷你。
  5. pip也叫包管理器,和conda的区别是,pip只管理python的包,而conda可以安装所有语言的包。而且conda可以管理python环境,pip不行。
  6. miniconda所有的操作命令皆在命令行中完成,没有GUI界面。而anaconda是有界面的。                  

原文链接:https://blog.csdn.net/weixin_43828245/article/details/124768518                     

 总之,Anaconda很大,内容很多,官网下载很慢,可以从国内清华镜像https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
下载Anaconda3-2023.09-0-Windows-x86_64.exe,安装完了有5个G。

具体可以参考 https://blog.csdn.net/CSDN_Admin0/article/details/134057091

Step 1: 下载Miniconda installer from the website 
Step 2: Run the installer from the terminal,

默认安装到了home directory,C:\Users\***\miniconda3。可能是没有设置环境,目前shell里面找不着。直接使用开始菜单里面的 Anaconda Prompt 

安装过后需要进行 环境变量 的配置,具体在哪设置环境变量请自行百度。

1)默认路径本身;2)默认路径+”\Scripts”;3)默认路径+”\Library\bin” 
例如默认路径为:”C:\Users\Administrator\Miniconda3”,那么需要添加的三个路径则是: 
1)C:\Users\Administrator\Miniconda3; 
2)C:\Users\Administrator\Miniconda3\Scripts; 
3)C:\Users\Administrator\Miniconda3\Library\bin 
第一个路径是Miniconda的根目录,也是最重要的路径!

————————————————

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.csdn.net/qq_33081367/article/details/81532796

 Miniconda是一款小巧的python环境管理工具,安装包大约只有50M多点,其安装程序中包含conda软件包管理器和Python。一旦安装了Miniconda,就可以使用conda命令安装任何其他软件工具包并创建环境等。

进入官网下载完成后,可进入开始菜单栏中点击Anaconda Promot,通过conda命令进行Miniconda的安装和配置环境变量。以下通过conda命令进行安装和配置:

配置清华源

此处需要配置一个清华的镜像服务器,以解决conda下载文件速度慢的问题。在Anaconda Promot中依次输入以下两条命令:

1. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

2. conda config --set show_channel_urls yes

可以输入以下命令查看所有工具包:

conda list

原文链接:https://zhuanlan.zhihu.com/p/133494097

Step 3: Install the basic packages that used in this book

安装书上用的 - ipythonnumpyscipypandasmatplotlib and jupyter notebook

用conda install命令安装,好像只能一个一个安装。
conda install ipython
conda install numpy
conda install scipy

Three ways to run Python code

  • Using Python shell or Ipython shell

在Anaconda Prompt里面输入python或者Ipython。The Ipython shell is richer than Python shell, such as Tab autocompletion, color-highlighted error messages, basic UNIX shell integration and so on.

  • Run Python script/file from command line

执行后缀为.py的脚本,任意text编辑器。

  • Using Jupyter Notebook

Anaconda Prompt命令行输入jupyter notebook, a local web page will pop up。比较慢。

1. 简介

Jupyter Notebook是以网页的形式打开,可以在网页页面中直接编写代码运行代码,代码的运行结果也会直接在代码块下显示的程序。如在编程过程中需要编写说明文档,可在同一个页面中直接编写,便于作及时的说明和解释。

2. 组成部分

① 网页应用

网页应用即基于网页形式的、结合了编写说明文档、数学公式、交互计算和其他富媒体形式的工具。简言之,网页应用是可以实现各种功能的工具。

② 文档

即Jupyter Notebook中所有交互计算、编写说明文档、数学公式、图片以及其他富媒体形式的输入和输出,都是以文档的形式体现的。

这些文档是保存为后缀名为.ipynbJSON格式文件,不仅便于版本控制,也方便与他人共享。

此外,文档还可以导出为:HTML、LaTeX、PDF等格式。

3. Jupyter Notebook的主要特点

① 编程时具有语法高亮缩进tab补全的功能。

② 可直接通过浏览器运行代码,同时在代码块下方展示运行结果。

③ 以富媒体格式展示计算结果。富媒体格式包括:HTML,LaTeX,PNG,SVG等。

④ 对代码编写说明文档或语句时,支持Markdown语法。

⑤ 支持使用LaTeX编写数学性说明。

原文链接:https://zhuanlan.zhihu.com/p/33105153

The Zen of Python

import this输出一堆文本,The Zen of Python, by Tim Peters

1.2 Python as A Calculator

本节讨论了如何在Python shell中运行命令来将 Python 用作计算器。

Python可以处理无穷大,1/∞写成1/math.inf;计算∞/∞是 math.inf/math.inf,结果是nan

基本数据类型:
int: Integers, such as 1, 2, 3, …
float: Floating-point numbers, such as 3.2, 6.4, …
complex: Complex numbers, such as 2 + 5j, 3 + 2j, …注意:在 Python 中,complex虚部使用 j 而不是 i 来表示。

In [16]: 2 + 5j
Out[16]: (2+5j)

可以用function type()来检查数据类型

In [19]: type(1234)
Out[19]: int
TRY IT! Find out the data type for 3.14.

In [20]: type(3.14)
Out[20]: float
TRY IT! Find out the data type for 2 + 5j.

In [21]: type(2 + 5j)
Out[21]: complex

1.3 管理包package

One feature makes Python really great is the various packages/modules developed by the community. managing packages is one of the most important skills you need to learn to fully take advantage of Python.
pip是安装Python包的最常见和最简单的方法。
pip help
pip install package_name                   安装最新版本的 package_name
pip install package_name==1.5          安装特定版本
pip install --upgrade package_name   将已安装的包升级到最新版本

pip uninstall package_name            卸载软件包

pip list                                   要获取所有已安装包的列表
pip show package_name     了解有关已安装包的详细信息,例如包的位置、所需的依赖项等

conda类似pip,也是包管理器。

源代码安装软件包
pip安装的都是 Python Package Index (PyPI)里面的项目。安装源文件的,里面有安装脚本 setup.py 和README。README会告诉 how to build and install the module。


python setup.py install
setup.py install             对于Windows用户

1.4 Jupyter Notebook 简介 

启动命令:jupyter notebook

1.5 逻辑表达式和运算符 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值