2017.7.11 && 一些不熟悉的函数 && 一些干货学习资料

来源:互联网 发布:数据备份的管理规范 编辑:程序博客网 时间:2024/06/07 01:34

1.创建单位阵

d = np.eye(2)        # Create a 2x2 identity matrixprint d              # Prints "[[ 1.  0.]                     #          [ 0.  1.]]"

2.创建随机阵

e = np.random.random((2,2)) # Create an array filled with random valuesprint e                     # Might print "[[ 0.91940167  0.08143941]                            #               [ 0.68744134  0.87236687]]"

3.3整型和切片同时访问数组时,访问结果会降阶

a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])row_r1 = a[1, :]    # Rank 1 view of the second row of a  row_r2 = a[1:2, :]  # Rank 2 view of the second row of aprint row_r1, row_r1.shape  # Prints "[5 6 7 8] (4,)"print row_r2, row_r2.shape  # Prints "[[5 6 7 8]] (1, 4)"col_r1 = a[:, 1]col_r2 = a[:, 1:2]print col_r1, col_r1.shape  # Prints "[ 2  6 10] (3,)"print col_r2, col_r2.shape  # Prints "[[ 2]                            #          [ 6]                            #          [10]] (3, 1)"

python-numpy-tutorial汉语版

numpy tutorial 详细教程汉语版

这个知乎帖子上都是干货

原创粉丝点击