zoukankan      html  css  js  c++  java
  • ndarry对象的属性

     1 #导入numpy
     2 import numpy as np 
     3 #创建一维数组
     4 a = np.array([1,2,3,4])
     5 print(a)
     6 #创建二维数组
     7 b = np.random.randint(4,10,size=(2,3))
     8 print(b)
     9 #创建三维数组
    10 c = np.random.randn(2,3,4)
    11 print(c)
    12 #ndim属性
    13 print('ndim:',a.ndim,b.ndim,c.ndim)
    14 #shape属性
    15 print('shape:',a.shape,b.shape,c.shape)
    16 #dtype属性
    17 print('dtype:',a.dtype,b.dtype,c.dtype)
    18 #size元素的总个数
    19 print('size:',a.size,b.size,c.size)
    20 #itemsize每个元素所占的字节
    21 print('itemsize:',a.itemsize,b.itemsize,c.itemsize)
     1 [1 2 3 4]
     2 [[4 4 8]
     3  [8 6 6]]
     4 [[[-0.04322546  0.37600869 -0.84201739  0.3652211 ]
     5   [ 0.30035931  0.54828284  0.26615364 -0.49428617]
     6   [ 0.10315291  0.07493424  0.27695642  0.1780474 ]]
     7 
     8  [[ 0.46234703  0.07898361 -1.2045445   0.61272457]
     9   [-0.15794512  0.64909964  0.02984023 -0.57428904]
    10   [ 0.03801586 -1.31788363  0.64976292  1.07791379]]]
    11 ndim: 1 2 3
    12 shape: (4,) (2, 3) (2, 3, 4)
    13 dtype: int32 int32 float64
    14 size: 4 6 24
    15 itemsize: 4 4 8
    正是江南好风景
  • 相关阅读:
    Bootstrap 插件收集
    target和currentTarget
    微信小程序
    flex
    vue中使用icon和打包
    rem的使用
    vue中使用sass和compass
    vue父子组件传递参数
    weex
    常用软件&&网址
  • 原文地址:https://www.cnblogs.com/monsterhy123/p/12594968.html
Copyright © 2011-2022 走看看