pwtools.common.str_arr

pwtools.common.str_arr(arr, fmt='%.16e', delim='    ', zero_eps=None, eps=np.float64(2.220446049250313e-16))[source]

Convert array arr to nice string representation for printing.

Parameters:
  • arr (array_like) – 1d or 2d array

  • fmt (str) – format specifier, all entries of arr are formatted with that

  • delim (str) – delimiter

  • eps (float) – Print values as 0.0 where abs(value) < eps. If eps < 0.0, then disable this.

Return type:

str

Notes

Essentially, we replicate the core part of np.savetxt.

Examples

>>> a=rand(3)
>>> str_arr(a, fmt='%.2f')
'0.26 0.35 0.97'
>>> a=rand(2,3)
>>> str_arr(a, fmt='%.2f')
'0.13 0.75 0.39\n0.54 0.22 0.66'
>>> print(str_arr(a, fmt='%.2f'))
0.13 0.75 0.39
0.54 0.22 0.66