这是数组:
>>> data
>>>array([[[[ -3.3042624 , -34.29845047, -92.78063965],
[-19.51710592, -70.68330269, -90.28064089]],
[[ -3.3042624 , -34.29845047, -92.78063965],
[ 12.31963874, -70.68330269, -87.78064089]]],
[[[ -6.36676407, -37.65069962, -59.52416229],
[ 11.32474047, -70.07037429, -59.52416067]],
[[ -6.36676407, -37.65069962, -59.52416229],
[-17.40294709, -72.80634454, -57.02416067]]]])
数组的结构:
data.shape
(2, 2, 2, 3)
切片实验–冒号和0:
>>> data[0,:,:,:] # 第一级I
[125]:
array([[[ -3.3042624 , -34.29845047, -92.78063965],
[-19.51710592, -70.68330269, -90.28064089]],
[[ -3.3042624 , -34.29845047, -92.78063965],
[ 12.31963874, -70.68330269, -87.78064089]]])
>>> data[:,0,:,:]#第二层II
[130]:
array([[ -3.3042624 , -34.29845047, -92.78063965],
[-19.51710592, -70.68330269, -90.28064089]])
>>> data[:,:,1,:]#第三层III
[145]:
array([[[-19.51710592, -70.68330269, -90.28064089],
[ 12.31963874, -70.68330269, -87.78064089]],
[[ 11.32474047, -70.07037429, -59.52416067],
[-17.40294709, -72.80634454, -57.02416067]]])
>>> data[:,:,:,0]#第四层IIII
[146]:
array([[[ -3.3042624 , -19.51710592],
[ -3.3042624 , 12.31963874]],
[[ -6.36676407, 11.32474047],
[ -6.36676407, -17.40294709]]])
怎么用for遍历第三层呢?(遍历诸点)
def Screws(Data):
# FidP = Pdata3(fidName)
Pc = Data[:,:,0,:]
Pz = Data[:,:,1,:]
fids = Data.shape[0]
for i in range(fids):
for ii in range(2):
PC = Pc[i][ii]
PZ = Pz[i][ii]
# AddPoint(PZ,"PZ",3)
P2P = np.linalg.norm(PC - PZ)
seg = 4
Axis_p2 = Lpcoord(PC,PZ)
# AddPoint(Axis_p2)
Screws.boneP = sRayCast(Axis_p2,PC, "Bonetempt")
p2pCyl(PC,Screws.boneP,2,'screwCyl',5,8,0,0,"red",1)
return
献上我的代码!