Skip to main content
remove irrelevant shift-key tag
Link
phuclv
  • 43.1k
  • 16
  • 189
  • 552
added 4 characters in body
Source Link
sten
  • 7.5k
  • 11
  • 51
  • 75

I have numpy array like this, where I have one column and one row of ZEROS :

 ([[0. , 2.8, 3.5, 0. , 2.5, 1. , 0.8],
   [0. , 0. , 0. , 0. , 0. , 0. , 0. ],
   [3.5, 2.5, 0. , 0. , 2.8, 1.3, 1.1],
   [3.6, 3.8, 3.3, 0. , 2.5, 0.6, 0.4],
   [2.5, 1.5, 2.8, 0. , 0. , 3.1, 1.9],
   [1. , 0.8, 1.3, 0. , 3.1, 0. , 2.8],
   [0.8, 1.6, 1.1, 0. , 1.9, 2.8, 0. ]])

I want to shift the zero-row to the top and the zero-column either to the left or remove it :

 ([[0. , 0. , 0. , 0. , 0. , 0. ]
   [0. , 2.8, 3.5, 2.5, 1. , 0.8],
   [3.5, 2.5, 0. , 2.8, 1.3, 1.1],
   [3.6, 3.8, 3.3, 2.5, 0.6, 0.4],
   [2.5, 1.5, 2.8, 0. , 3.1, 1.9],
   [1. , 0.8, 1.3, 3.1, 0. , 2.8],
   [0.8, 1.6, 1.1, 1.9, 2.8, 0. ]])

any quick and easy way to do it ? BTW I know the col&row-number, so i doesnt have to search for it.

I have numpy array like this, where I have one column and row of ZEROS :

 ([[0. , 2.8, 3.5, 0. , 2.5, 1. , 0.8],
   [0. , 0. , 0. , 0. , 0. , 0. , 0. ],
   [3.5, 2.5, 0. , 0. , 2.8, 1.3, 1.1],
   [3.6, 3.8, 3.3, 0. , 2.5, 0.6, 0.4],
   [2.5, 1.5, 2.8, 0. , 0. , 3.1, 1.9],
   [1. , 0.8, 1.3, 0. , 3.1, 0. , 2.8],
   [0.8, 1.6, 1.1, 0. , 1.9, 2.8, 0. ]])

I want to shift the zero-row to the top and the zero-column either to the left or remove it :

 ([[0. , 0. , 0. , 0. , 0. , 0. ]
   [0. , 2.8, 3.5, 2.5, 1. , 0.8],
   [3.5, 2.5, 0. , 2.8, 1.3, 1.1],
   [3.6, 3.8, 3.3, 2.5, 0.6, 0.4],
   [2.5, 1.5, 2.8, 0. , 3.1, 1.9],
   [1. , 0.8, 1.3, 3.1, 0. , 2.8],
   [0.8, 1.6, 1.1, 1.9, 2.8, 0. ]])

any quick and easy way to do it ? BTW I know the col&row-number, so i doesnt have to search for it.

I have numpy array like this, where I have one column and one row of ZEROS :

 ([[0. , 2.8, 3.5, 0. , 2.5, 1. , 0.8],
   [0. , 0. , 0. , 0. , 0. , 0. , 0. ],
   [3.5, 2.5, 0. , 0. , 2.8, 1.3, 1.1],
   [3.6, 3.8, 3.3, 0. , 2.5, 0.6, 0.4],
   [2.5, 1.5, 2.8, 0. , 0. , 3.1, 1.9],
   [1. , 0.8, 1.3, 0. , 3.1, 0. , 2.8],
   [0.8, 1.6, 1.1, 0. , 1.9, 2.8, 0. ]])

I want to shift the zero-row to the top and the zero-column either to the left or remove it :

 ([[0. , 0. , 0. , 0. , 0. , 0. ]
   [0. , 2.8, 3.5, 2.5, 1. , 0.8],
   [3.5, 2.5, 0. , 2.8, 1.3, 1.1],
   [3.6, 3.8, 3.3, 2.5, 0.6, 0.4],
   [2.5, 1.5, 2.8, 0. , 3.1, 1.9],
   [1. , 0.8, 1.3, 3.1, 0. , 2.8],
   [0.8, 1.6, 1.1, 1.9, 2.8, 0. ]])

any quick and easy way to do it ? BTW I know the col&row-number, so i doesnt have to search for it.

Source Link
sten
  • 7.5k
  • 11
  • 51
  • 75

shift numpy array column and row?

I have numpy array like this, where I have one column and row of ZEROS :

 ([[0. , 2.8, 3.5, 0. , 2.5, 1. , 0.8],
   [0. , 0. , 0. , 0. , 0. , 0. , 0. ],
   [3.5, 2.5, 0. , 0. , 2.8, 1.3, 1.1],
   [3.6, 3.8, 3.3, 0. , 2.5, 0.6, 0.4],
   [2.5, 1.5, 2.8, 0. , 0. , 3.1, 1.9],
   [1. , 0.8, 1.3, 0. , 3.1, 0. , 2.8],
   [0.8, 1.6, 1.1, 0. , 1.9, 2.8, 0. ]])

I want to shift the zero-row to the top and the zero-column either to the left or remove it :

 ([[0. , 0. , 0. , 0. , 0. , 0. ]
   [0. , 2.8, 3.5, 2.5, 1. , 0.8],
   [3.5, 2.5, 0. , 2.8, 1.3, 1.1],
   [3.6, 3.8, 3.3, 2.5, 0.6, 0.4],
   [2.5, 1.5, 2.8, 0. , 3.1, 1.9],
   [1. , 0.8, 1.3, 3.1, 0. , 2.8],
   [0.8, 1.6, 1.1, 1.9, 2.8, 0. ]])

any quick and easy way to do it ? BTW I know the col&row-number, so i doesnt have to search for it.