Home > Back-end >  logarithmic operation on numpy array
logarithmic operation on numpy array

Time:10-13

I have a NumPy array as shown below.

array(['0.0189', '0.0200', '0.0212', '0.0225', '0.0239', '0.0253',
       '0.0268', '0.0284', '0.0302', '0.0320', '0.0339', '0.0360',
       '0.0381', '0.0405', '0.0429', '0.0455', '0.0482', '0.0512',
       '0.0542', '0.0575', '0.0610', '0.0647', '0.0686', '0.0728',
       '0.0772', '0.0818', '0.0868', '0.0920', '0.0976', '0.1035',
       '0.1097', '0.1164', '0.1234', '0.1309', '0.1388', '0.1472',
       '0.1560', '0.1655', '0.1755', '0.1861', '0.1973', '0.2093',
       '0.2219', '0.2353', '0.2496', '0.2647', '0.2807', '0.2976',
       '0.3156', '0.3347', '0.3549', '0.3764', '0.3991', '0.4233',
       '0.4489'], dtype=object)

The array name is result.I need to do logrithmic operation on this array.Below is my code.

20*(np.log10(float(result)/1.44))

When running this code, I obtained an error as shown below.

TypeError                                 Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 20*(np.log10(float(result)/1.44))

TypeError: only size-1 arrays can be converted to Python scalars

can someone help me to solve this issue.

CodePudding user response:

You cannot convert this array to array of floats using float, you need to use astype method. Here is example use:

result.astype(np.float64)
  • Related