Last change
on this file since 7837 was
7837,
checked in by mungkasi, 13 years ago

Again, adding some codes for 1d problems on debris avalanche and periodic waves.

File size:
575 bytes

Line  

1  ## module swap 

2  ''' swapRows(v,i,j). 

3  Swaps rows i and j of vector or matrix [v]. 

4  

5  swapCols(v,i,j). 

6  Swaps columns i and j of matrix [v]. 

7  

8  def swapRows(v,i,j): 

9  if len(v.getshape()) == 1: v[i],v[j] = v[j],v[i] 

10  else: 

11  temp = v[i].copy() 

12  v[i] = v[j] 

13  v[j] = temp 

14  ''' 

15  

16  def swapRows(v,i,j): 

17  if len(v.flat) == 2: 

18  v[i],v[j] = v[j],v[i] 

19  else: 

20  temp = v[i].copy() 

21  v[i] = v[j] 

22  v[j] = temp 

23  

24  def swapCols(v,i,j): 

25  temp = v[:,j].copy() 

26  v[:,j] = v[:,i] 

27  v[:,i] = temp 

Note: See
TracBrowser
for help on using the repository browser.