I am in the process of trying to teach myself python so I am very new to this. My code is pretty simple. I just have a numpy array that I have randomly generated with integers. My code looks like this
arr = np.random.randint(100, size=(5,5))
print(arr)
When it prints it prints with brackets around it like this
[[98 87 45 5 67]
[33 39 1 40 96]
[97 55 85 2 65]
[18 28 32 55 21]
[96 46 14 87 28]]
How do I remove all of the brackets so it is only the numbers with the spaces between?
What about using Pandas?
import numpy as np
import pandas as pd
arr = np.random.randint(100, size=(5,5))
df = pd.DataFrame(arr)
print(df.to_string(header=False, index=False))
45 40 99 8 20
29 18 54 52 51
94 52 84 61 17
44 54 38 48 62
4 76 95 73 46
Try:
for el in arr:
print(' '.join(el.astype(str)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With