zoukankan      html  css  js  c++  java
  • np.newaxis用法详解

    np.newaxis,增加维度

    In [1]: np.linspace(1, 10, 10)
    Out[1]: array([  1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.])
    
    In [2]: np.linspace(1, 10, 10)[np.newaxis,:]
    Out[2]: array([[  1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.]])
    
    In [3]: np.linspace(1, 10, 10)[:,np.newaxis]
    Out[3]:
    array([[  1.],
           [  2.],
           [  3.],
           [  4.],
           [  5.],
           [  6.],
           [  7.],
           [  8.],
           [  9.],
           [ 10.]])
    
    In [4]: np.linspace(1, 10, 10).shape
    Out[4]: (10,)
    
    In [5]: np.linspace(1, 10, 10)[np.newaxis,:].shape
    Out[5]: (1, 10)
    
    In [6]: np.linspace(1, 10, 10)[:,np.newaxis].shape
    Out[6]: (10, 1)
    
  • 相关阅读:
    表单
    框架
    表格
    列表
    标签
    封装类(包装类)
    常见类 --Object
    日志
    异常
    选择结构
  • 原文地址:https://www.cnblogs.com/twfb/p/7685402.html
Copyright © 2011-2022 走看看