'How to export numpy array without brackets

I am new to Python and I want to export a NumPy array without brackets.

For example,

enter image description here

to

enter image description here

Note that there are an odd number of elements in the array.

Thank you very much!!!



Solution 1:[1]

Didn't understand what did you mean by exporting? or you just need to print them? If you want to print them without brackets you can do the following:

    import numpy as np

    a = np.asarray([[1,2],[2,3],[3,4]])
               
    for item in a:
       a_str = np.array2string(item, precision=2, separator=' ')
       print(' ' + a_str[1:-1])

    print(a)

Solution 2:[2]

To save a NumPy array to a file, you can use numpy's savetxt:

np.savetxt('test.out', fmt='%d', arr)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sadikul Haque Sadi
Solution 2 Anis R.