Efficient way to pick/delete a list of rows/columns in a matrix in Mathematica

前端 未结 2 1490
生来不讨喜
生来不讨喜 2020-12-17 05:04

This question is in a way a continuation of the question I asked here:Simple way to delete a matrix column in Mathematica to which @belisarius and @Daniel provided very help

2条回答
  •  时光说笑
    2020-12-17 05:36

    You can also use explicit ranges in a way that is fairly efficient. They may provide some more flexibility. Here is your example.

    a = RandomInteger[1000, {5000, 5000}];
    
    Timing[b = Drop[a, {101}, {101}];]
    

    Out[66]= {0.041993, Null}

    Timing[
      c = a[[Join[Range[100], Range[102, 5000]], 
       Join[Range[100], Range[102, 5000]]]];]
    

    Out[67]= {0.061991, Null}

    c == b
    

    Out[62]= True

    I would also suggest use of Span except offhand I do not see how to get it to work in this setting.

    Daniel Lichtblau Wolfram Research

提交回复
热议问题