How to print numpy objects without line breaks

I register input function arguments using

logging.debug('Input to this function = %s', inspect.getargvalues(inspect.currentframe())[3]) 

But I do not want line breaks to be inserted into numpy objects. numpy.set_printoptions(linewidth=np.nan) removes some, but line breaks are still inserted into 2D objects such as

 array([[ 0.84148239, 0.71467895, 0.00946744, 0.3471317 ], [ 0.68041249, 0.20310698, 0.89486761, 0.97799646], [ 0.22328803, 0.32401271, 0.96479887, 0.43404245]]) 

I want it to be like this:

 array([[ 0.84148239, 0.71467895, 0.00946744, 0.3471317 ], [ 0.68041249, 0.20310698, 0.89486761, 0.97799646], [ 0.22328803, 0.32401271, 0.96479887, 0.43404245]]) 

How can i do this? Thanks.

+6
source share
1 answer

Given an array of x , you can print it without line breaks with

 import numpy as np x_str = np.array_repr(x).replace('\n', '') print(x_str) 

or alternatively using the np.array2string function instead of np.array_repr .

I'm not sure if there is an easy way to remove strings from a string representation or numpy arrays. However, you can always delete them after the conversion,

 input_args = inspect.getargvalues(inspect.currentframe())[3] logging.debug('Input to this function = %s', repr(input_args).replace('\n', '')) 
+3
source

Source: https://habr.com/ru/post/983920/


All Articles