weixin_45537682 2021-04-26 11:11 采纳率: 0%
浏览 44

尝试写一个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的长度

 

 

 

  • 写回答

5条回答 默认 最新

  • CSDN专家-黄老师 2021-04-26 11:17
    关注
    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
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码