I have some hard times learning Python array handling with numpy.
I have a .csv file which contains in one column unsigned integer data which represents binary values from an analog digital converter. I would like to convert this unsigned integer values in 12 bit binary representation using Python inside a jupyter notebook.
I tried several ways of implementing it, but I still fail...
here is my code:
import pandas as pd
df = pd.read_csv('my_adc_values.csv', delimiter ='\s+', header=None, usecols=[19])
decimalValues = df.values
print(decimalValues.shape)
so far so good... I have all my adc data column values in the decimalValues numpy array.
Now, I would like to iterate through the array and convert the integers in the array to a binary representation:
import numpy as np
# destination array of shape of source array
binaryValues = np.zeros(decimalValues.shape)
for i in range(len(decimalValues)):
    print(decimalValues[i])
    binaryValues[i]=(bin(decimalValues[i]))    
print(binaryValues)
With this code I get the error message
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-890444040b2e> in <module>()
      6 for i in range(len(decimalValues)):
      7     print(decimalValues[i])
----> 8     binaryValues[i]=(bin(decimalValues[i]))
      9 
     10 print(binaryValues)
TypeError: only integer scalar arrays can be converted to a scalar index
I tried several different solutions, but none of them worked. It seems as if I have a massive misunderstanding of numpy arrays.
I'm looking for a tip on how to solve my described problem. I found some threads, describing the the mentioned error message. I suspected, it had something to do with the shape of the source/destination arrays. therefore, I initialized the destination array with the same shape as the source. It did not help...
Thank you, Maik
'000000010111'? Or do you want abytesstring likeb'\x00\x17', which is 23 in Big Endian.