numpy学习笔记(一):numpy数组创建

import numpy as np
from numpy import pi

# creation 1

a = np.arange(24).reshape(4, 6)
print(a)

print(a.shape)
print(a.itemsize)
print(a.dtype)

b = np.arange(1, 10, 2)
print(b)

print(b.size)
print(b.shape)

# creation 2

c = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32)
print(c)
print(c.shape)
print(c.itemsize)

# creation 3
d = np.zeros((3, 4), dtype=np.int64)
print(d)
d = d.reshape(4, 3)
# d.reshape(4, 3)  d doesn't change
print(d)

# creation 4
e = np.empty((3, 4))      # uninitialized
print(e)

# creation 5
f = np.linspace(0, 9.5, 20).reshape(4, 5)
print(f)

x = np.linspace(0, 2*pi, 5)
print("x = ", x)
y = np.sin(x)
print("y = ",y)

# creation 6   random
g = np.random.randint(0, 100, (4, 5), dtype=np.int64)
print(g)

h = np.random.random_integers(1, 100, (4, 5));
print(h)

i = np.random.rand(2, 4)  # [0, 1]
print(i)

j = np.random.randn(3, 4) # N
print(j)

猜你喜欢

转载自blog.csdn.net/qq_30986521/article/details/80815657