数据文件:pattern1.ktx
import numpy as np
data = np.fromfile('pattern1.ktx', dtype=np.byte)
print ('endianness:', hex(data[12:13]))
结果: TypeError:只能将整数标量数组转换为标量索引
看起来够简单吗?我不明白。如何解决这个问题?谢谢。
这个怎么样?
b = np.frombuffer(np.array(data[12:12+4], dtype=np.byte), dtype=np.uint32)
print ('endianess:', hex(b))
相同错误。如何解决?
答案 0 :(得分:0)
好的,由于某种原因它会返回一个列表,因此必须对其进行索引。
const [alpha, setAlpha] = React.useState(0.0)
const [devicePosition, setDevicePosition] = React.useState({
centerX: 0.0,
centerY: 0.0,
deviceX1: 0.0,
deviceY1: 0.0,
deviceX2: 0.0,
deviceY2: 0.0,
})
const [timer, setTimer] = React.useState(null)
let isMounted = true
React.useEffect(() => {
const handleOrientation = e => setAlpha(e.alpha)
window.addEventListener("deviceorientation", handleOrientation, true)
updateDevicePosition() //make rest call on mounting
return () => {
window.removeEventListener("deviceorientation", handleOrientation)
isMounted = false
}
}, [])
async function updateDevicePosition() {
try {
const result = await fetch("http://192.168.10.233:34599/")
const data = await result.json()
if (isMounted) { //so you aren't setting state on an unmounted component
setDevicePosition({
centerX: data[0].x,
centerY: data[0].y,
deviceX1: data[1].x,
deviceY1: data[1].y,
deviceX2: data[2].x,
deviceY2: data[2].y,
})
}
} catch (e) {
console.error(e)
}
if (isMounted) {
clearTimeout(timer)
setTimer(setTimeout(updateDevicePosition, 200))
}
}
已修复错误。