import numpy as np
# Create a new array from which we will select elements
a = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])
print(a) # prints "array([[ 1, 2, 3],
# [ 4, 5, 6],
# [ 7, 8, 9],
# [10, 11, 12]])"
# Create an array of indices
b = np.array([0, 2, 0, 1])
print(b)
# Select one element from each row of a using the indices in b
print(a[np.arange(4), b]) # Prints "[ 1 6 7 11]"
# Mutate one element from each row of a using the indices in b
a[np.arange(4), b] += 10
print(a) # prints "array([[11, 2, 3],
#######################################################################################
a = np.array([[1,2], [3, 4], [5, 6]])
bool_idx = (a > 2)
print(bool_idx)
print(a[bool_idx]) # print true
print(a[a > 2]) # Prints "[3 4 5 6]"
##############################Datatypes########################################
print()
x = np.array([1, 2]) # Let numpy choose the datatype
print(x.dtype) # Prints "int32"
x = np.array([1.0, 2.0]) # Let numpy choose the datatype
print(x.dtype) # Prints "float64"
x = np.array([1, 2], dtype=np.int64) # Force a particular datatype
print(x.dtype)
print("***********************************************")
x1 = np.linspace(1,10)
x2 = np.linspace(1,10,10)
print(x1)
print("len(x1)=", len(x1))
print(x2)
print("len(x2)=", len(x2))
#np.random.rand()#生成生成[0,1)之间随机浮点数
print(np.random.rand())
print(np.random.rand(1))
print(np.random.rand(2, 3))
print(np.random.rand(5))
print()
for i in range(0, 10):
print(np.random.randn())
# 标准正态分布随机样本
print(np.random.standard_normal(2))
print(np.random.standard_normal((2,3)))
print(np.random.standard_normal([2,3]))
print(np.random.standard_normal([2,3]).shape)
#随机整数
print(np.random.randint(2))
print(np.random.randint(2,size=5))
print(np.random.randint(2,6))
print(np.random.randint(2,6,size=15))
print(np.random.randint(2,size=(2,3)))
print(np.random.randint(2,6,(2,3)))
print()
list1 = [1,2,3,4,5]
np.random.shuffle(list1)
print(list1)
arr = np.arange(9).reshape(3,3)
print(arr)
print(np.random.shuffle(arr))
print(arr)