利用python进行数据分析1_numpy的基本操作,建模基础
import numpy as np # 生成指定维度的随机多维数据 data=np.random.rand(2,3) print(data) print(type(data)) 结果: [[0.11959428 0.52816495 0.31736705 ] [ 0.75400637 0.26683732 0.54080784 ]] < class ' numpy.ndarray ' > View Code print('维度个数',data.ndim) print('各维度大小',data.shape) print('数据类型',data.dtype) 结果: 维度个数 2 各维度大小 ( 2, 3 ) 数据类型 float64 View Code 补充: import numpy as np # 生成指定维度的随机多维数据 data2=np.arange(1,10,2)#间隔为2 print(data2) print('元素个数',data2.size) # 5 ndarray,N维数组对象(矩阵) 所有元素必须是相同类型 ndim属性:维度个数 shape属性:各维度大小 dtype属性:数据类型 创建ndarray #list转换为ndarray l=range(10) data=np.array(l) print(data)#[0 1 2 3 4 5 6 7 8 9]