天天看点

numpy_数组的基本访问和修改

文章目录

  • ​​example1:​​

example1:

import numpy as np
from numpy import random

a1=random.randn(9,10)
print(a1)
print(a1[2,5])
print(a1[6,3])
print(a1[3:5,4:6])
print(a1[3:5,[1,2,4]])
#filter elements in two dimesion ndarray:
print(np.where(a1>1,10,-10))
print(a1[a1[:,:]>1])
#the detail of the process:
array_randn=random.randn(20)
array_bool=array_randn>1
print(array_bool)
filter_result=array_randn[array_bool]
print(filter_result)