Skip to content

Commit

Permalink
Good stuff - format can now be sent as additional parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bojan Niceno committed Mar 25, 2017
1 parent 74b0a77 commit 8f305d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 9 additions & 2 deletions PYTHON/Display/print_array.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#==========================================================================
def print_array(a):
def print_array(*args):
#--------------------------------------------------------------------------

if len((args)) == 1:
a = args[0]
format = "%7.2f"
else:
a = args[0]
format = args[1]

print('Array ['+('%d' %a.shape[0])+']')
rows = a.shape[0]
for i in range(0,rows):
print('%15.8e ' %a[i])
print(format %a[i])

return # end of function
14 changes: 9 additions & 5 deletions PYTHON/Display/print_matrix.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#==========================================================================
def print_matrix(a):
def print_matrix(*args):
#--------------------------------------------------------------------------

if len((args)) == 1:
a = args[0]
format = "%7.2f"
else:
a = args[0]
format = args[1]

print('Matrix['+('%d' %a.shape[0])+']['+('%d' %a.shape[1])+']')
rows = a.shape[0]
cols = a.shape[1]

for i in range(0,rows):
for j in range(0,cols):
if a[i,j] == 0:
print(' . ', end='')
else:
print(('%7.2f' %a[i,j]), end='')
print((format %a[i,j]), end='')
print('')
print('')

Expand Down

0 comments on commit 8f305d5

Please sign in to comment.