lundi 20 mars 2023

TypeError: %X format: an integer is required, not numpy.ndarray How to solve?

enter image description here
from __future__ import print_function
import numpy as np
def tohex(val, nbits):
 return hex((val + (1 <<nbits)) % (1 <<nbits))
array=np.load('C:/Tool/Python_pattern/agilev3_new/inout_pattern_layer52/in_52.npy')
#print(array.shape)
print(array.dtype)

# array[#][Row][Column][Channel] #1 52 52 384
fp = open("in_52.dat", "w")

for ch in range(384):
 data=array[ch]
 #print(data.dtype)
 #print(data)
 print(str("%08X" %(data)))
 
 if data<0:
  data=2**32+data
  #fp.write(str("%08X" %(data)))
  fp.write(str("%08X" %(data)))
 else:
  #fp.write(str("%08X" %(data)))
  fp.write(str("%08X" %(data)))
 fp.write("\n")
fp.close()

Here is the code I am using. I am trying to get a data file in powershell. But it always show error.

When I do in powershell.

PS C:\Tool\Python_pattern\agilev3_new\inout_pattern_layer52> python for_bias_patterm_rowachannel_base.py

I got this

Traceback (most recent call last):
  File "for_bias_patterm_rowachannel_base.py", line 16, in <module>
    print(str("%08X" %(data)))
TypeError: %X format: an integer is required, not numpy.ndarray

Aucun commentaire:

Enregistrer un commentaire