0

datafile: pattern1.ktx

import numpy as np

data = np.fromfile('pattern1.ktx', dtype=np.byte)

print ('endianness:', hex(data[12:13]))

Result: TypeError: only integer scalar arrays can be converted to a scalar index

Looks simple enough? I'm not getting it though. How to fix this? Thank You.

How about this one?

    b = np.frombuffer(np.array(data[12:12+4], dtype=np.byte), dtype=np.uint32)
    print ('endianess:', hex(b))

Same error. How to fix?

2
  • 1
    hex(data[12]) Commented Jun 25, 2019 at 15:51
  • ya, that's it, brainfreeze. Reaching for the coffee just now. Thank You. Commented Jun 25, 2019 at 15:57

1 Answer 1

0

OK, it returns a list for some reason, so have to index it.

b = np.frombuffer(np.array(data[12:12+4], dtype=np.byte), dtype=np.uint32)
print ('endianess:', hex(b[0]))

Error fixed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.