2

Suppose I have an array

k= array([[1, 2, 3, 4, 5],
          [5, 6, 7, 8, 9],
          [2, 5, 4, 7, 3],
          [4, 7, 6, 8, 2],
          [1, 2, 4, 3, 6],
          [7, 8, 9, 5, 4]])

Assuming that after computing for each columns in an array I got array([0.6,0.4,0.75,0.2,0.75]) respectively, such that:

computation on column1 i.e. computation on array([1,5,2,4,1,7]) results in 0.6, computation on column2 i.e. computation on array([2,6,5,7,2,8]) results in 0.4, computation on column3 i.e. computation on array([3,7,4,6,4,9]) results in 0.75, and so on.

Let the computed list be m. such that

m=array([0.6,0.4,0.75,0.2,0.75])

So far I have computed for single columns in array k. Now I would like to group the elements in list m based on the largest floating point element in the list m and compute again on k. For example:

m[2]=m[4]=0.75 (largest number in the array), that would mean index 2 and index 4 of column in array k is largest. So keeping that index number common I would like to group k[:,2] with k[:,0],k[:,2] with k[:,1],k[:,2] with k[:,3] and similarly k[:,4] with k[:,0],k[:,4] with k[:,1],k[:,4] with k[:,3] and compute again on k,

such that grouping k[:,2] with k[:,0] means :

k0_2=array([[1,3],          k1_2=array([[2,3],          k3_2=array([[4,3],
            [5,7],                      [6,7],                      [8,7],
            [2,4],                      [5,4],                      [7,4],
            [4,6],                      [7,6],                      [8,6],
            [1,4],                      [2,4],                      [3,4],  
            [7,9]])                     [8,9]])                     [5,9]])

k0_4=array([[1,5],          k1_4=array([[2,5],          k3_4=array([[4,5],
            [5,9],                      [6,9],                      [8,9],
            [2,9],                      [5,3],                      [7,3],
            [4,2],                      [7,2],                      [8,2],
            [1,6],                      [2,6],                      [3,6],  
            [7,4]])                     [8,4]])                     [5,4]])

Can anyone please give me any clue regarding grouping column indices of array k based on max value of list m as shown above .

7
  • I don't quite understand your paragraph with the sentence "So keeping that index number common...". What do you mean by "compute again on k"? And how do you get the groups you've described in that sentence? Could you make this a bit clearer, for example describe to us in more details the steps we would take to get these groups? Commented Sep 12, 2015 at 11:34
  • By saying i would like to keep the index number common i meant that all I want to keep the index number of greater element in the list M common and use that index, to group with non max index as shown above. Commented Sep 12, 2015 at 11:47
  • I am trying to understand what the paragraph I mentioned means and how you work out this grouping. If that means you also need to explain how you got the array m then sure. Commented Sep 12, 2015 at 11:50
  • Based on lower approximation i got m. You will get good enough literature on that topic. Commented Sep 12, 2015 at 12:15
  • Your question has a lot of irrelevant detail but doesn't specify what you actually want. What does the required answer look like? Do you want a list of 6-by-2 arrays? If so, what order should they come in? If not, what is the form of the answer? Commented Sep 12, 2015 at 15:39

2 Answers 2

1

Does this help?

import numpy as np

k= np.array(
    [[1, 2, 3, 4, 5],
     [5, 6, 7, 8, 9],
     [2, 5, 4, 7, 3],
     [4, 7, 6, 8, 2],
     [1, 2, 4, 3, 6],
     [7, 8, 9, 5, 4]])

cols=[2,4]
others = [c for c in range(k.shape[1]) if c not in cols]
groups = [k[:,[o, c]] for c in cols for o in others]
for g in groups:
    print(g)
    print('')

This gives me

[[1 3]
 [5 7]
 [2 4]
 [4 6]
 [1 4]
 [7 9]]

[[2 3]
 [6 7]
 [5 4]
 [7 6]
 [2 4]
 [8 9]]

[[4 3]
 [8 7]
 [7 4]
 [8 6]
 [3 4]
 [5 9]]

[[1 5]
 [5 9]
 [2 3]
 [4 2]
 [1 6]
 [7 4]]

[[2 5]
 [6 9]
 [5 3]
 [7 2]
 [2 6]
 [8 4]]

[[4 5]
 [8 9]
 [7 3]
 [8 2]
 [3 6]
 [5 4]]

I think there's a typographical error in your k_04 array. I think k_04[2,10 should be 3, not 9, isn't that so?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot :) and yeah my mistake. It's an error anyway thanks bro
0

Here is another solution which I along with one of my friend figured it out :

import numpy as np

k= np.array(
    [[1, 2, 3, 4, 5],
     [5, 6, 7, 8, 9],
     [2, 5, 4, 7, 3],
     [4, 7, 6, 8, 2],
     [1, 2, 4, 3, 6],
     [7, 8, 9, 5, 4]])

cols=[2,4]
kl = np.delete(k, np.s_[cols],1)

 for i in range(len(cols)):
     for j in range(len(kl[0])):
          print np.column_stack((k[:,cols[i]],kl[:,j]))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.