有什么办法 replace/substitute uint8 数据中的数组数据点
Is there any way to replace/substitute an array data points in uint8 data
我有这个数据
old= array([[171, 171, 171, ..., 170, 170, 170],
[171, 171, 171, ..., 170, 170, 170],
[171, 171, 171, ..., 170, 170, 170],
...,
[ 17, 17, 17, ..., 17, 17, 17],
[ 17, 17, 17, ..., 17, 17, 17],
[ 17, 17, 17, ..., 17, 17, 17]], dtype=uint8)
在这个数据中我需要放置我的外部数组数据点
new= array([ 65, 108, 105, 32, 105, 115, 32, 116, 104, 101, 32, 66, 101,
115, 116, 32, 105, 110, 32, 116, 104, 101, 32, 119, 111, 114,
108, 100, 32, 121, 101, 101, 104, 104, 104, 104, 104, 104, 104,
104])
在旧数组的第一行,这样输出就像
old= array([[ 65, 108, 105, 32, 105, 115, 32, 116, 104, 101, 32,66,101,
115, 116, 32, 105, 110, 32, 116, 104, 101, 32, 119, 111, 114,
108, 100, 32, 121, 101, 101, 104, 104, 104, 104, 104, 104, 104,
104, ..., 170, 170, 170],
[171, 171, 171, ..., 170, 170, 170],
[171, 171, 171, ..., 170, 170, 170],
...,
[ 17, 17, 17, ..., 17, 17, 17],
[ 17, 17, 17, ..., 17, 17, 17],
[ 17, 17, 17, ..., 17, 17, 17]], dtype=uint8)
我假设您使用的是 numpy?有
old[0] = new[0]
工作? (假设您想将旧数组的第一行替换为
新数组的第一行)
要替换数组的第一行:
old[0] = new
应该这样做:
old[0, :len(new)] = new
我有这个数据
old= array([[171, 171, 171, ..., 170, 170, 170],
[171, 171, 171, ..., 170, 170, 170],
[171, 171, 171, ..., 170, 170, 170],
...,
[ 17, 17, 17, ..., 17, 17, 17],
[ 17, 17, 17, ..., 17, 17, 17],
[ 17, 17, 17, ..., 17, 17, 17]], dtype=uint8)
在这个数据中我需要放置我的外部数组数据点
new= array([ 65, 108, 105, 32, 105, 115, 32, 116, 104, 101, 32, 66, 101,
115, 116, 32, 105, 110, 32, 116, 104, 101, 32, 119, 111, 114,
108, 100, 32, 121, 101, 101, 104, 104, 104, 104, 104, 104, 104,
104])
在旧数组的第一行,这样输出就像
old= array([[ 65, 108, 105, 32, 105, 115, 32, 116, 104, 101, 32,66,101,
115, 116, 32, 105, 110, 32, 116, 104, 101, 32, 119, 111, 114,
108, 100, 32, 121, 101, 101, 104, 104, 104, 104, 104, 104, 104,
104, ..., 170, 170, 170],
[171, 171, 171, ..., 170, 170, 170],
[171, 171, 171, ..., 170, 170, 170],
...,
[ 17, 17, 17, ..., 17, 17, 17],
[ 17, 17, 17, ..., 17, 17, 17],
[ 17, 17, 17, ..., 17, 17, 17]], dtype=uint8)
我假设您使用的是 numpy?有
old[0] = new[0]
工作? (假设您想将旧数组的第一行替换为 新数组的第一行)
要替换数组的第一行:
old[0] = new
应该这样做:
old[0, :len(new)] = new