坑记--四维矩阵切片实验

这是数组:

>>> 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]]])

2021-04-29修改

怎么用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

献上我的代码!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jumbo Jing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值