get the i-th slice of the k-th dimension in a numpy array

前端 未结 5 1077
抹茶落季
抹茶落季 2020-12-10 15:35

I have an n-dimensional numpy array, and I\'d like to get the i-th slice of the k-th dimension. There must be something better than

5条回答
  •  情深已故
    2020-12-10 16:09

    I am not sure if it will work for k dim but it does for 2 dim

    a.take(i,axis=k)
    

提交回复
热议问题