i have a vector "char" of type |S1 like in the example below:
masked_array(data=[b'E', b'U', b'3', b'7', b'6', b'8', b' ', b' ', b' ', b' '],
mask=False,
fill_value=b'N/A',
dtype='|S1')
I want to get the string in it, in this example 'EU3768'
This example is taken from a netcdf file. Library used is netCDF4.
Further question: Why is there a b in front of all single letters?
Thanks for your help :)
First of all let's answer the most basic question: What is the meaning of the b in front of each letter. The b simply indicates that the character string is in bytes. The internal format of the data is being stored encoded as utf-8. So to convert it back to a string it must be decoded. So with that as a preamble, the following code will do the trick.
I am assuming that you can extract data from the masked_array. Then perform the following operations:
This could of course be performed in a single line of code as follows: