I am trying to generate an array out of a file with numpy.genfromtxt
.
File is like:
16.37.235.200|59009|514|16.37.235.153|
17.37.235.200|59009|514|18.37.235.153|
And I get an array like:
['16.37.235.200' '17.37.235.200']
But I want the array to be like that:
[16.37.235.200,17.37.235.200]
Here is your original array:
x = np.array(['16.37.235.200', '17.37.235.200'])
which is displayed like this when printed:
print(x)
>>> ['16.37.235.200' '17.37.235.200']
In order to display it with comma as a delimiter and without quotes around strings we can use np.array2string
:
print(np.array2string(x, separator=',', formatter={'str_kind': lambda x: x}))
>>> [16.37.235.200,17.37.235.200]
I don't like that lambda x: x
formatter but couldn't come up with something better to remove the quotes.
You can find more here: How to pretty-printing a numpy.array without scientific notation and with given precision?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.