|
|
|
|
|
|
摘要:
NumPy 提供了很多统计函数,用于从数组中查找最小元素,最大元素,百分位标准差和方差等。 numpy.amin() 用于计算数组中的元素沿指定轴的最小值。 numpy.amax() 用于计算数组中的元素沿指定轴的最大值。 import numpy as np a = np.array([[3,7, 阅读全文
posted @ 2020-01-22 20:48
吴裕雄
阅读(221)
推荐(0)
摘要:
NumPy 算术函数包含简单的加减乘除: add(),subtract(),multiply() 和 divide()。 需要注意的是数组必须具有相同的形状或符合数组广播规则。 import numpy as np a = np.arange(9, dtype = np.float_).reshap 阅读全文
posted @ 2020-01-22 20:39
吴裕雄
阅读(244)
推荐(0)
摘要:
NumPy 包含大量的各种数学运算的函数,包括三角函数,算术运算的函数,复数处理函数等。 NumPy 提供了标准的三角函数:sin()、cos()、tan()。 import numpy as np a = np.array([0,30,45,60,90]) print ('不同角度的正弦值:') 阅读全文
posted @ 2020-01-22 20:25
吴裕雄
阅读(179)
推荐(0)
摘要:
这些函数在字符数组类(numpy.char)中定义。 add() 对两个数组的逐个字符串元素进行连接 multiply() 返回按元素多重连接后的字符串 center() 居中字符串 capitalize() 将字符串第一个字母转换为大写 title() 将字符串的每个单词的第一个字母转换为大写 l 阅读全文
posted @ 2020-01-22 20:20
吴裕雄
阅读(225)
推荐(0)
摘要:
bitwise_and() 函数对数组中整数的二进制形式执行位与运算。 import numpy as np print ('13 和 17 的二进制形式:') a,b = 13,17 print (bin(a), bin(b)) print ('\n') print ('13 和 17 的位与:' 阅读全文
posted @ 2020-01-22 16:35
吴裕雄
阅读(250)
推荐(0)
摘要:
import numpy as np a = np.arange(8) print ('原始数组:') print (a) print ('\n') b = a.reshape(4,2) print ('修改后的数组:') print (b) numpy.ndarray.flat 是一个数组元素迭代 阅读全文
posted @ 2020-01-22 16:29
吴裕雄
阅读(250)
推荐(0)
摘要:
import numpy as np a = np.arange(6).reshape(2,3) print ('原始数组是:') print (a) print ('\n') print ('迭代输出元素:') for x in np.nditer(a): print (x, end=", " ) 阅读全文
posted @ 2020-01-22 16:06
吴裕雄
阅读(177)
推荐(0)
摘要:
广播(Broadcast)是 numpy 对不同形状(shape)的数组进行数值计算的方式, 对数组的算术运算通常在相应的元素上进行。 如果两个数组 a 和 b 形状相同,即满足 a.shape == b.shape,那么 a*b 的结果就是 a 与 b 数组对应位相乘。这要求维数相同,且各维度的长 阅读全文
posted @ 2020-01-22 15:57
吴裕雄
阅读(173)
推荐(0)
摘要:
import numpy as np x = np.array([[1, 2], [3, 4], [5, 6]]) y = x[[0,1,2], [0,1,0]] print (y) import numpy as np x = np.array([[ 0, 1, 2],[ 3, 4, 5],[ 6 阅读全文
posted @ 2020-01-22 15:51
吴裕雄
阅读(215)
推荐(0)
摘要:
ndarray 数组可以基于 0 - n 的下标进行索引,切片对象可以通过内置的 slice 函数,并设置 start, stop 及 step 参数进行,从原数组中切割出一个新数组。 import numpy as np a = np.arange(10) s = slice(2,7,2) # 从 阅读全文
posted @ 2020-01-22 15:46
吴裕雄
阅读(171)
推荐(0)
摘要:
import numpy as np x = np.arange(5) print (x) import numpy as np # 设置了 dtype x = np.arange(5, dtype = float) print (x) import numpy as np x = np.arang 阅读全文
posted @ 2020-01-22 15:43
吴裕雄
阅读(145)
推荐(0)
摘要:
import numpy as np x = [1,2,3] a = np.asarray(x) print (a) import numpy as np x = (1,2,3) a = np.asarray(x) print (a) import numpy as np x = [(1,2,3), 阅读全文
posted @ 2020-01-22 15:34
吴裕雄
阅读(178)
推荐(0)
摘要:
import numpy as np x = np.empty([3,2], dtype = int) print (x) import numpy as np # 默认为浮点数 x = np.zeros(5) print(x) # 设置类型为整数 y = np.zeros((5,), dtype 阅读全文
posted @ 2020-01-22 15:29
吴裕雄
阅读(181)
推荐(0)
摘要:
NumPy 数组的维数称为秩(rank),秩就是轴的数量,即数组的维度,一维数组的秩为 1,二维数组的秩为 2,以此类推。 在 NumPy中,每一个线性的数组称为是一个轴(axis),也就是维度(dimensions)。比如说,二维数组相当于是两个一维数组,其中第一个一维数组中每个元素又是一个一维数 阅读全文
posted @ 2020-01-22 15:24
吴裕雄
阅读(184)
推荐(0)
摘要:
下表列举了常用 NumPy 基本类型。 名称 描述 bool_ 布尔型数据类型(True 或者 False) int_ 默认的整数类型(类似于 C 语言中的 long,int32 或 int64) intc 与 C 的 int 类型一样,一般是 int32 或 int 64 intp 用于索引的整数 阅读全文
posted @ 2020-01-22 15:18
吴裕雄
阅读(235)
推荐(0)
摘要:
NumPy 最重要的一个特点是其 N 维数组对象 ndarray,它是一系列同类型数据的集合,以 0 下标为开始进行集合中元素的索引。 ndarray 对象是用于存放同类型元素的多维数组。 ndarray 中的每个元素在内存中都有相同存储大小的区域。 ndarray 内部由以下内容组成: 一个指向数 阅读全文
posted @ 2020-01-22 15:10
吴裕雄
阅读(133)
推荐(0)
摘要:
import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, optimizers, metrics def preprocess(x, y): """数据处理函 阅读全文
posted @ 2020-01-22 13:18
吴裕雄
阅读(265)
推荐(0)
摘要:
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himmeblau(x): return (x[0]**2 + x[1] - 11)**2 + (x[0] + 阅读全文
posted @ 2020-01-22 11:46
吴裕雄
阅读(253)
推荐(0)
posted @ 2020-01-22 11:34
吴裕雄
阅读(183)
推荐(0)
摘要:
import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.constant(2.) b2 = tf.constant(1.) with tf.GradientTape(p 阅读全文
posted @ 2020-01-22 11:28
吴裕雄
阅读(221)
推荐(0)
摘要:
import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) y = tf.constant([2, 0]) with tf.GradientTape() as 阅读全文
posted @ 2020-01-22 11:23
吴裕雄
阅读(208)
推荐(0)
摘要:
import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.constant([1]) with tf.GradientTape() as tape: tape.wa 阅读全文
posted @ 2020-01-22 11:12
吴裕雄
阅读(155)
推荐(0)
摘要:
import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) y = tf.constant([2, 0]) with tf.GradientTape() as 阅读全文
posted @ 2020-01-22 11:05
吴裕雄
阅读(319)
推荐(0)
摘要:
import tensorflow as tf a = tf.linspace(-10., 10., 10) a with tf.GradientTape() as tape: tape.watch(a) y = tf.sigmoid(a) grads = tape.gradient(y, [a]) 阅读全文
posted @ 2020-01-22 10:57
吴裕雄
阅读(187)
推荐(0)
摘要:
import tensorflow as tf w = tf.constant(1.) x = tf.constant(2.) y = x * w with tf.GradientTape() as tape: tape.watch([w]) y2 = x * w grad1 = tape.grad 阅读全文
posted @ 2020-01-22 10:46
吴裕雄
阅读(348)
推荐(0)
|
|