I have a numpy array of characters and when I write it to file it writes as:
['K' 'R' 'K' 'P' 'T' 'T' 'K' 'T' 'K' 'R' 'G' 'L']
I want it to write with just the letters and without the brackets or quotations i.e. as:
KRKPTTKTKRGL
I have looked at numpy documentation and from what I have gathered the solution is a chararray however it looks like this is not as functional as a normal array.
Any help would be great. Thanks!
If you just have a numpy array then why not convert it to a string directly for writing to your file? You can do this using str.join
which accepts an iterable (list, numpy array, etc).
import numpy as np
arr = np.array(['K', 'R', 'K', 'P', 'T', 'T', 'K', 'T', 'K', 'R', 'G', 'L'])
s = ''.join(arr)
# KRKPTTKTKRGL
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