http://cs231n.github.io/python-numpy-tutorial/

Python is a great general-purpose programming language on its own, but with the help of a few popular libraries (numpy, scipy, matplotlib) it becomes a powerful environment for scientific computing.

#PYTHON基础
数据类型
特殊:list,dictionary,set,tuples

运算符
字符串操作
x ** 2 平方

流程控制语句
if,while,for
使用缩进表示语言结构

函数
定义和使用

类定义和使用
默认参数self的理解
类的方法与普通的函数只有一个特别的区别——它们必须有一个额外的第一个参数名称,但是在调用这个方法的时候你不为这个参数赋值,Python会提供这个值。self指向对象(instance)本身

#python如何安装第三方软件包
1 下载源码包
在github 或者 pypi上找到源码。找到源码格式大概都是 zip、tar.zip、tar格式的压缩包。解压这些包,进入解压好的文件夹,通常会看见一个 setup.py 的文件。打开命令行,进入该文件夹。运行
python setup.py install
这个命令,就能把这个第三库安装到系统里,也就是你的 Python 路径,windows大概是在 C:\Python2.7\Lib\site-packages。
Linux会在 /usr/local/lib/python2.7/dist-packages。
Mac 应该在 /Library/Python/2.7/site-packages

2 使用pip or easy_install
pip install flask
pip uninstall flask
pip intall flask-master.zip 使用pip安装下载的zip文件的源码包

#附录
Python2.6不支持 set的列举定义 animals={'cat','dog'} 会有语法错误。
3与2.7的版本有较大的不同,不能向下兼容。
Somewhat confusingly, Python 3.0 introduced many backwards-incompatible changes to the language, so code written for 2.7 may not work under 3.4 and vice versa.

遇到问题,请多使用documentation
https://docs.python.org/2/

python字符集的问题
存储统一使用unicode字符集

#PYSTROM
更改pystrom使用的python版本
Project>Interpreter

如果要使用中文注释,使用#coding=utf-8

在run中执行py文件

可以选中语句,然后右键run the selection in the console

可以单步调试

# coding=utf-8
# variables' types
# list
tmp2 = [1, 2, 3, "myItem"]
# you can use negative value for indexing
print tmp2[-1]
tmp2.append(234)
for item in tmp2:
print item # dictionary
tmp3 = {1: "nice", "key2": "bad"}
print tmp3[1]
tmp3["3"] = "test"
del tmp3[1]
for item in tmp3:
print item
print tmp3[item] # set
animals = {'cat', 'dog'}
animals.add('erer')
animals.add("cat")
animals.remove("dog")
print 12 in animals # tuple
tuple5 = (1, 2)
tmp6 = {tuple5, 12}
print (1, 2) in tmp6 # operator
tmp = 2**4
print tmp # string
name = "rex"
print 'Hello, %s' % name # control structure
# condition
if tmp == 12:
print "yes"
elif tmp < 0:
print 'Hello, %d' % tmp
else:
print "no" # loop
count = 0
while count < 9:
print 'The count is:', count
count += 1 # define a function
def sign(x):
name1 = "rex"
if x > 0:
return 'positive'
elif x < 0:
print 'Hello, %s' % name1
return 'negative'
else:
return 'zero' # defining classes
class Greeter(object):
# Constructor
def __init__(self, name1):
self.name = name1 # Create an instance variable # Instance method
def greet(self, loud=False):
if loud:
print 'HELLO, %s!' % self.name.upper()
else:
print 'Hello, %s' % self.name # create an instance of a class
tmpClass = Greeter("rex")
# 所以加点访问的,可能是包名/也可能是类的某个instance名

  

# coding=utf-8
# numpy
import numpy as np
tmp = np.array([1, 2, 3])
print tmp[1]
tmp2 = np.random.random((1, 2))
# 比 matlab 要繁琐的多,创建矩阵,要使用tuple
print tmp2
a = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
# get a row
print a[1,:]
print a[0,:]
print a[:, 1]
print np.arange(3) # 0 1 2
# calculate the items
# Mutate one element from each row of a using the indices in b
b = np.array([1, 2, 3])
a[np.arange(3), b] += 10
print a

  

附录:python and numpy的更多相关文章

  1. [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决

    这篇文章主要讲述Python如何安装Numpy.Scipy.Matlotlib.Scikit-learn等库的过程及遇到的问题解决方法.最近安装这个真是一把泪啊,各种不兼容问题和报错,希望文章对你有所 ...

  2. python安装numpy和pandas

    最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装numpy和pandas因为linux环境没有外网遇到了很多问题就记下来了.首要条件,python版本必须 ...

  3. python和numpy的版本、安装位置

    命令行下查看python和numpy的版本和安装位置 1.查看python版本 方法一: python -V 注意:‘-V‘中‘V’为大写字母,只有一个‘-’ 方法二: python --versio ...

  4. python之numpy的安装

    这是我第一次写博客,我的第一次打算送给python的numpy库的安装指导,这是我看到一位大神的博客后产生的启发,真是控制不住自己,必须得写一下. 第一次安装numpy浪费了我一个下午,结果还没安装好 ...

  5. 如何查看安装python和numpy的版本

    命令行下查看python和numpy的版本和安装位置 1.查看python版本 方法一: python -V 注意:‘-V‘中‘V’为大写字母,只有一个‘-’ 方法二: python --versio ...

  6. 命令行下查看python和numpy的版本和安装位置

    命令行下查看python和numpy的版本和安装位置 1.查看python版本 方法一: python -V 注意:‘-V‘中‘V’为大写字母,只有一个‘-’ 方法二: python --versio ...

  7. 图文并茂的Python教程-numpy.pad

    图文并茂的Python教程-numpy.pad np.pad()常用与深度学习中的数据预处理,可以将numpy数组按指定的方法填充成指定的形状. 声明: 需要读者了解一点numpy数组的知识np.pa ...

  8. [转] python安装numpy和pandas

    最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装numpy和pandas因为linux环境没有外网遇到了很多问题就记下来了.首要条件,python版本必须 ...

  9. [转]python与numpy基础

    来源于:https://github.com/HanXiaoyang/python-and-numpy-tutorial/blob/master/python-numpy-tutorial.ipynb ...

  10. 【转载】python安装numpy和pandas

    转载:原文地址 http://www.cnblogs.com/lxmhhy/p/6029465.html 最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装 ...

随机推荐

  1. AngularJS 表达式中添加过滤器实例

    过滤器可以通过一个管道字符(|)和一个过滤器添加到表达式中 历练实例: <!DOCTYPE html><html><head><meta http-equiv ...

  2. C#继承的多态性

    C#继承的多态性 当一个类A派生出新类B时,这个基类A在新类B中可以表现为不同的类型:用作它自己的类型.基类型,或者在实现接口时用作接口类型,我们将这种情况称为多态性. C#中的每种类型都是多态性的, ...

  3. print_Matrix(Python实现)

    num = int(input("Please input a number:")) #矩阵最外层的值 n = num*2 Matrix = [([0] * n)for i in ...

  4. 【主席树上二分】bzoj5361: [Lydsy1805月赛]对称数

    随机化选讲例题 题目大意 小 Q 认为,偶数具有对称美,而奇数则没有.给定一棵 n 个点的树,任意两点之间有且仅有一条直接或间接路径.这些点编号依次为 1 到 n,其中编号为 i 的点上有一个正整数 ...

  5. 【例题收藏】◇例题·I◇ Snuke's Subway Trip

    ◇例题·I◇ Snuke's Subway Trip 题目来源:Atcoder Regular 061 E题(beta版) +传送门+ 一.解析 (1)最短路实现 由于在同一家公司的铁路上移动是不花费 ...

  6. Redis高可用

    redis高可用只要在于三个方面 主从复制 哨兵机制 集群机制 主从复制 主从复制作用: 1.数据冗余:主从复制实现了数据的热备份,是持久化之外的一种数据冗余方式.2.故障恢复:当主节点出现问题时,可 ...

  7. 面向对象封装的web服务器

    import socket import re import os import sys # 由于前面太繁琐,可以用类封装一下,也可以分几个模块 class HttpServer(object): d ...

  8. datatable行内内容太长,有时不自动换行解决方法

    加一个css属性即可 style = "word-wrap:break-word;" js代码: "render": function (data, type, ...

  9. 【CodeBase】PHP打印所有用户自定义常量

    print_r(get_defined_constants(true)['user']);

  10. CLK_SWR=0xe1

    STM8 时钟初始化 主时钟切换寄存器(CLK_SWR) http://www.stmcu.org/document/detail/index/id-200090 stm8寄存器数据手册链接