• python的imread、newaxis


    一:imread

    用来读取图片,返回一个numpy.ndarray类型的多维数组,具有两个参数:

    参数1 filename, 读取的图片文件名,可以使用相对路径或者绝对路径,但必须带完整的文件扩展名(图片格式后缀)

    参数2 flags, 一个读取标记,用于选择读取图片的方式,默认值为IMREAD_COLOR,flag值的设定与用什么颜色格式读取图片有关
    import cv2
    path = 'E:Flow classificationemail_train1.jpg'
    image = cv2.imread(path)
    print(image)
    print(type(image))

     二:newaxis

    用来增加数组维度,如下:

    import numpy as np
    
    a=np.array([1,2,3,4,5,6,7,8,9])
    print(a.shape)
    print(a)
    
    b = a[:,np.newaxis]
    print(b.shape)
    print(b)
    
    c = b[:,:,np.newaxis]
    print(c.shape)
    print(c)
    
    d = c[:,:,:,np.newaxis]
    print(d.shape)
    print(d)
    

     输出结果如下:

    (9,)
    [1 2 3 4 5 6 7 8 9]
    (
    9, 1) [[1] [2] [3] [4] [5] [6] [7] [8] [9]]
    (
    9, 1, 1) [[[1]] [[2]] [[3]] [[4]] [[5]] [[6]] [[7]] [[8]] [[9]]] (9, 1, 1, 1) [[[[1]]] [[[2]]] [[[3]]] [[[4]]] [[[5]]] [[[6]]] [[[7]]] [[[8]]] [[[9]]]]

    ***************不积跬步无以至千里***************

  • 相关阅读:
    UVAlive5135_Mining Your Own Business
    UVAlive3523_Knights of the Round Table
    UVA10759_Dice Throwing
    POJ3177_Redundant Paths
    UVA11027_Palindromic Permutation
    Codechef_JULY14
    UVAlive4255_Guess
    UVA10054_The Necklace
    杜教BM
    【2018徐州网络赛】Morgana Net (矩阵快速幂)
  • 原文地址:https://www.cnblogs.com/liangshian/p/11788427.html
Copyright © 2020-2023  润新知