尝试写一个numpy的切片(python)

return an array containing the elements of v but without the first and last elements, and the remaining elements in reverse order.

The code should print

[3 1 2 4]

 

import numpy as np

v = np.array([9, 4, 2, 1, 3, 8])

new_v = v[1:-1][::-1]

print(new_v)

 

new_v 括号的右边要小于12 characters的长度

 

 

 

import numpy as np

arr = np.arange(12)
print 'array is:', arr

slice_one = arr[:4]
print 'slice begins at 0 and ends at 4 is:', slice_one

slice_two = arr[7:10]
print 'slice begins at 7 and ends at 10 is:', slice_two

slice_three = arr[0:12:4]
print 'slice begins at 0 and ends at 12 with step 4 is:', slice_three

 

上面的那个是实现了的,也是对的,但你最后那个到底是在问什么,看不懂

您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

v[1:-1][::-1]是可以,可就是长度要求(less than 12 characters long)

非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!

速戳参与调研>>>https://t.csdnimg.cn/Kf0y