Python数据分析:numpy创建数组

Python数据分析:numpy创建数组

numpy.empty 创建指定形状、数据类型且未初始化的数组
numpy.empty(shape, dtype = float, order = 'C')
  • shape 数组形状
  • dtype 数据类型(可选)
  • order 有"C"和"F"两个选项,分别代表,行优先和列优先,在计算机内存中的存储元素的顺序
numpy.zeros 创建指定大小的全0数组
numpy.zeros(shape, dtype = float, order = 'C')
numpy.ones 创建指定大小的全1数组
numpy.ones(shape, dtype = None, order = 'C')
random.randn 创建标准正态分布数组
from numpy import *

# 创建 randn(size) 服从 X~N(0,1) 的正态分布随机数组
a=random.randn(2,3)
print(a)

运行结果:
在这里插入图片描述

random.randint 创建随机分布整数型数组
from numpy import *

a=random.randint(100,200,(3,3))
print(a)

运行结果:
在这里插入图片描述

arange 创建数组
import numpy as np

a = np.arange(10)
b = np.arange(10, 20)
c = np.arange(10, 20, 2)

print(a)
print(b)
print(c)

运行结果:
在这里插入图片描述

eye 创建对角矩阵数组
import numpy as np
a = np.eye(5)

print(a)

运行结果:
在这里插入图片描述
参考:http://www.runoob.com/numpy

猜你喜欢

转载自blog.csdn.net/weixin_41792682/article/details/89461480