Home > Software design >  How to export numpy array without brackets
How to export numpy array without brackets

Time:03-17

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!!!

CodePudding user response:

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)

CodePudding user response:

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

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