假设你有一个numpy数组和一个列表:
>>> a = np.array([1,2,2,1]).reshape(2,2)
>>> a
array([[1, 2],
[2, 1]])
>>> b = [0, 10]
Run Code Online (Sandbox Code Playgroud)
我想替换数组中的值,以便将1替换为0,将2替换为10.
我在这里发现了类似的问题 - http://mail.python.org/pipermail//tutor/2011-September/085392.html
但使用此解决方案:
for x in np.nditer(a):
if x==1:
x[...]=x=0
elif x==2:
x[...]=x=10
Run Code Online (Sandbox Code Playgroud)
给我一个错误:
ValueError: assignment destination is read-only
Run Code Online (Sandbox Code Playgroud)
我想这是因为我无法写入一个numpy数组.
PS numpy数组的实际大小是514乘504,列表是8.
我已经设置了弹出窗口,但是我想将它放在按钮(View v)下面,需要点击它才能打开它:
public void showPopup(Context c, View v){
int[] location = new int[2];
v.getLocationOnScreen(location);
ViewGroup base = (ViewGroup) getView().findViewById(R.id.pup_pattern);
LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View pupLayout = inflater.inflate(R.layout.linearlayout_popup, base);
final PopupWindow pup = new PopupWindow(pupLayout, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
int x = location[0] - (int) ((pupLayout.getWidth() - v.getWidth()) / 2 ); // --> pupLayout.getWidth() gives back -2?
int y = location[1] + v.getHeight() + 10;
pup.setFocusable(true);
pup.showAtLocation(v, Gravity.NO_GRAVITY, x, y);
}
Run Code Online (Sandbox Code Playgroud)
有人有想法得到措施吗?
我正在使用 vulkan 计算着色器开发路径跟踪器。我实现了一个表示边界卷层次结构的树。BVH 的想法是最小化需要执行光线交叉测试的对象数量。
#1 幼稚的实现
我的第一个实现非常快,它将树向下遍历到BVH 树的单个叶子。但是,射线可能会与多个叶子相交。这段代码会导致一些三角形没有被渲染(尽管它们应该)。
int box_index = -1;
for (int i = 0; i < boxes_count; i++) {
// the first box has no parent, boxes[0].parent is set to -1
if (boxes[i].parent == box_index) {
if (intersect_box(boxes[i], ray)) {
box_index = i;
}
}
}
if (box_index > -1) {
uint a = boxes[box_index].ids_offset;
uint b = a + boxes[box_index].ids_count;
for (uint j = a; j < b; j++) { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为'my_op'编写一个自定义渐变函数,为了示例,它只包含对tf.identity()的调用(理想情况下,它可以是任何图形).
import tensorflow as tf
from tensorflow.python.framework import function
def my_op_grad(x):
return [tf.sigmoid(x)]
@function.Defun(a=tf.float32, python_grad_func=my_op_grad)
def my_op(a):
return tf.identity(a)
a = tf.Variable(tf.constant([5., 4., 3., 2., 1.], dtype=tf.float32))
sess = tf.Session()
sess.run(tf.initialize_all_variables())
grad = tf.gradients(my_op(a), [a])[0]
result = sess.run(grad)
print(result)
sess.close()
Run Code Online (Sandbox Code Playgroud)
不幸的是我收到以下错误:
Traceback (most recent call last):
File "custom_op.py", line 19, in <module>
grad = tf.gradients(my_op(a), [a])[0]
File "/Users/njk/tfm/lib/python3.5/site-packages/tensorflow/python/framework/function.py", line 528, in __call__
return call_function(self._definition, *args, **kwargs)
File "/Users/njk/tfm/lib/python3.5/site-packages/tensorflow/python/framework/function.py", line 267, in call_function
compute_shapes=False)
File "/Users/njk/tfm/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2285, in create_op
raise …
Run Code Online (Sandbox Code Playgroud) 提供端口转发对象
from kubernetes.stream import stream, portforward
pf = portforward(
k8s_client_v1.connect_get_namespaced_pod_portforward,
pod_name,
name_space,
ports=port
)
pf.socket(port)
Run Code Online (Sandbox Code Playgroud)
pf
是来自 family 的套接字对象AF_UNIX
。
我需要更好地了解是否AF_INET
必须实例化另一个系列套接字才能实现与kubectl
客户端相同的功能,例如:kubectl port-forward $pod_name $port
如果有人可以分享此类实现的任何片段,我预先表示感谢。
此时创建端口转发对象的灵感来自于这里
python ×3
android ×1
bounding-box ×1
glsl ×1
indexing ×1
kubernetes ×1
measurement ×1
numpy ×1
popupwindow ×1
raytracing ×1
sockets ×1
tensorflow ×1
vulkan ×1