• python机器学习库numpy---4.3、n维数组的创建(特殊数组)


    python机器学习库numpy---4.3、n维数组的创建(特殊数组)

    一、总结

    一句话总结:

    numpy中常用的特殊矩阵 主要有ones(全1)、zeros(全0)、eye(单位矩阵)、empty(未初始化)

    二、n维数组的创建(特殊数组)

    博客对应课程的视频位置:4.3、n维数组的创建(特殊数组)-范仁义-读书编程笔记
    https://www.fanrenyi.com/video/38/344

    4.3、n维数组的创建(特殊数组)

    numpy中常用的特殊矩阵 主要有ones(全1)、zeros(全0)、eye(单位矩阵)、empty(未初始化)

    In [2]:
    # 需要一个表示矩阵维度的元组做参数
    arr=np.ones((2,3))
    print(arr)
    
    [[1. 1. 1.]
     [1. 1. 1.]]
    
    In [4]:
    arr=np.zeros((3,2))
    print(arr)
    
    [[0. 0.]
     [0. 0.]
     [0. 0.]]
    
    In [5]:
    arr=np.eye(3)
    print(arr)
    
    [[1. 0. 0.]
     [0. 1. 0.]
     [0. 0. 1.]]
    
    In [6]:
    help(np.eye)
    
    Help on function eye in module numpy:
    
    eye(N, M=None, k=0, dtype=<class 'float'>, order='C')
        Return a 2-D array with ones on the diagonal and zeros elsewhere.
        
        Parameters
        ----------
        N : int
          Number of rows in the output.
        M : int, optional
          Number of columns in the output. If None, defaults to `N`.
        k : int, optional
          Index of the diagonal: 0 (the default) refers to the main diagonal,
          a positive value refers to an upper diagonal, and a negative value
          to a lower diagonal.
        dtype : data-type, optional
          Data-type of the returned array.
        order : {'C', 'F'}, optional
            Whether the output should be stored in row-major (C-style) or
            column-major (Fortran-style) order in memory.
        
            .. versionadded:: 1.14.0
        
        Returns
        -------
        I : ndarray of shape (N,M)
          An array where all elements are equal to zero, except for the `k`-th
          diagonal, whose values are equal to one.
        
        See Also
        --------
        identity : (almost) equivalent function
        diag : diagonal 2-D array from a 1-D array specified by the user.
        
        Examples
        --------
        >>> np.eye(2, dtype=int)
        array([[1, 0],
               [0, 1]])
        >>> np.eye(3, k=1)
        array([[0.,  1.,  0.],
               [0.,  0.,  1.],
               [0.,  0.,  0.]])
    
    
    In [7]:
    arr=np.empty((4,6))
    print(arr)
    
    [[3.854e-321 3.854e-321 2.945e-321 2.945e-321 2.925e-321 2.925e-321]
     [3.814e-321 3.814e-321 4.763e-321 4.763e-321 4.427e-321 4.427e-321]
     [4.664e-321 4.664e-321 5.336e-321 5.336e-321 5.810e-321 5.810e-321]
     [5.830e-321 5.830e-321 5.850e-321 5.850e-321 4.545e-321 4.545e-321]]
    
    In [ ]:
     
     
    我的旨在学过的东西不再忘记(主要使用艾宾浩斯遗忘曲线算法及其它智能学习复习算法)的偏公益性质的完全免费的编程视频学习网站: fanrenyi.com;有各种前端、后端、算法、大数据、人工智能等课程。
    博主25岁,前端后端算法大数据人工智能都有兴趣。
    大家有啥都可以加博主联系方式(qq404006308,微信fan404006308)互相交流。工作、生活、心境,可以互相启迪。
    聊技术,交朋友,修心境,qq404006308,微信fan404006308
    26岁,真心找女朋友,非诚勿扰,微信fan404006308,qq404006308
    人工智能群:939687837

    作者相关推荐

  • 相关阅读:
    Django知识总结(一)
    Django知识总结(二)
    Django知识总结(三)
    机器学习领域主要术语的英文表达
    Python的进程与线程--思维导图
    MySQL数据库--思维导图
    5.18 每日小三练
    5.14 每日小三练
    5.12 每日小三练
    5.9 每日小三练
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/13550026.html
Copyright © 2020-2023  润新知