02. 导数与梯度、矩阵运算性质、科学计算库numpy

一、数学基础

二、numpy

一、数学基础

关键字:求导、偏导、梯度、复合函数求导链式法则

矩阵的转置、矩阵加减、矩阵乘法【矩阵乘法不满足交换律】

二、numpy

#coding:utf-8

import numpy as np

print np.__version__

# 1- create narray

array = np.array([1,2,3],dtype=np.uint8)

print "array:",array

# 2- zeros

mat1 = np.zeros((2,3)) #(2,3) tuple

print "mat1:",mat1

# 3- 高维矩阵

mat2 = np.zeros((1,2,3,4))

print mat2.shape

print mat2.size

# 4- 标准矩阵运算

# (1) 标量与矩阵相乘

scalar = 2

mat = np.ones((2,3))

mat3 = scalar * mat

print "mat3:",mat3

# (2) 矩阵转置 mat.T

mat = np.zeros((2,3))

tmat = mat.T

print mat.shape,tmat.shape

mat4 = np.array((1,2,3))

print "mat4:",mat4

tmat4 = mat4.T

print mat4.shape,tmat4.shape

# (3) 矩阵的加法

print "add--------------------"

mat1 = np.array([[1,2],[3,4]])

mat2 = np.zeros((2,2))

mat3 = mat1 + mat2

print "mat3:",mat3

# (4) 矩阵的乘法

print "multi------------------"

mat1 = np.array([[1,2],[3,4]])

mat2 = np.ones((2,2))

mat3 = mat1.dot(mat2)

print "mat3:",mat3

原文地址:https://www.cnblogs.com/Years4Nancy/p/8492521.html

时间: 2024-08-28 19:42:11

02. 导数与梯度、矩阵运算性质、科学计算库numpy的相关文章

Python科学计算库-Numpy

科学计算库Numpy 处理数据 Year,WHO region,Country,Beverage Types,Display Value 1986,Western Pacific,Viet Nam,Wine,0 1986,Americas,Uruguay,Other,0.5 1985,Africa,Cte d'Ivoire,Wine,1.62 1986,Americas,Colombia,Beer,4.27 1987,Americas,Saint Kitts and Nevis,Beer,1.9

科学计算库Numpy基础操作

pycharm,python3.7,numpy版本1.15.1 2018年9月11日04:23:06 """ 科学计算库Numpy基础操作 时间:2018\9\11 0011 """ import numpy print("""\n------以矩阵的方式读取数据------\n ------------genfromtxt函数('文件路径',delimiter = '分隔符',dtype = 读取方式)------

python 科学计算库NumPy—矩阵运算

NumPy库的核心是矩阵及其运算. 使用array()函数可以将python的array_like数据转变成数组形式,使用matrix()函数转变成矩阵形式. 基于习惯,在实际使用中较常用array而少用matrix来表示矩阵. 然后即可使用相关的矩阵运算了 import numpy as np a = [[1,2,3],[4,5,5],[4,5,5]] len = a.shape[0] #多维数组的行数 print(a.dtype) #输出元素类型 #另外也还可以使用切片方式来处理数组 然后是

科学计算库numpy

world_alcohol.txt文件内容 Year,WHO region,Country,Beverage Types,Display Value 1986,Western Pacific,Viet Nam,Wine,0 1986,Americas,Uruguay,Other,0.5 1985,Africa,Cte d'Ivoire,Wine,1.62 1986,Americas,Colombia,Beer,4.27 1987,Americas,Saint Kitts and Nevis,Be

python 科学计算库NumPy—tile函数

在学习knn分类算法的过程中用到了tile函数,有诸多的不理解,记录下来此函数的用法.   函数原型:numpy.tile(A,reps) #简单理解是此函数将A进行重复输出 其中A和reps都是array_like的参数,A可以是:array,list,tuple,dict,matrix以及基本数据类型int,string,float以及bool类型,reps的类型可以是tuple,list,dict,array,int,bool,但不可以是float,string,matrix类型. 计较常

科学计算库Numpy,

Numpy 一,数据结构 数据类型: ndarray import numpy world_alchol = numpy.genfromtxt('world_alchol.txt',delimiter=',',dtype=str) print(type(world_alchol)) print(world_alchol) print(help(numpy.genfromtxt)) 创建一维的数组: vector = numpy.array([5,10,15,20]) 创建二维的数组: matri

C++科学计算库GSL及其配置

分享一下我老师大神的人工智能教程吧.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net C++科学计算库GSL及其配置        很有可能某一天,在程序里面你会需要用到一些函数,比如 Γ 函数,β 函数,还有普通的对数吖之类的,你会想到什么,不会是#i nclude <math.h>吧?计算机科学发展了这么多年,已经有了许许多多优秀的科学计算的函数库,涵盖了各种方面,你所要做的,就是导入它们,把参数代入,然后等待

python科学计算之numpy

1.np.logspace(start,stop,num): 函数表示的意思是;在(start,stop)间生成等比数列num个 eg: import numpy as np print np.logspace(1,4,4) 结果为: [    10.    100.   1000.  10000.] 2. np.fromstring('admin',dtype=np.int8):函数的作用是将字符串装换成对应的ascii值 import numpy as np print np.fromstr

转载~如何在Pycharm中安装numpy等科学计算库

转载自机器小人z windows下如何快速优雅的使用python的科学计算库? Python是一种强大的编程语言,其提供了很多用于科学计算的模块,常见的包括numpy.scipy.pandas和matplotlib.要利用Python进行科学计算,就需要一一安装所需的模块,而这些模块可能又依赖于其它的软件包或库,因而安装和使用起来相对麻烦.幸好有人专门在做这一类事情,将科学计算所需要的模块都编译好,然后打包以发行版的形式供用户使用,Anaconda就是其中一个常用的科学计算发行版. 我们从网站(