Skip to content Skip to sidebar Skip to footer

Printing Numpy Arrays Without Brackets

predictions = [x6,x5,x4,x3,x2,x1] predictions Calling the above list yields the following arrays: [array([782.36739152]), array([783.31415872]), array([726.90474426]), array([

Solution 1:

If you change predictions to numpy array then, you can use print(*predictions.flatten(), sep=', ').

You can try as following:

import numpy as np

predictions = np.array([np.array([782.36739152]),
                        np.array([783.31415872]),
                        np.array([726.90474426]),
                        np.array([772.08910103]),
                        np.array([728.79734162]),
                        np.array([753.67887657])])


print(*predictions.flatten(), sep=', ')

Output:

782.36739152, 783.31415872, 726.90474426, 772.08910103, 728.79734162, 753.67887657

Solution 2:

The result would be a string.

>>> ' '.join(str(x[0]) for x in predicitons)
'782.36739152 783.31415872 726.90474426 772.08910103 728.79734162 753.67887657'

You could also round the result, e.g. str(round(x[0], 2)).

Solution 3:

Solution 4:

Numpy arrays almost always come with the brackets. If you do not want brackets around each number, but good with them being around the whole array, the following code might help:

', '.join([str(lst[0]) for lst in predictions])

The delimiter could be modified to suit your purpose.

Hope it helps.

Post a Comment for "Printing Numpy Arrays Without Brackets"