variable-assignment

Problem assigning values to Mat array in OpenCV 2.3 - seems simple

隐身守侯 提交于 2019-12-23 10:37:13
问题 Using the new API for OpenCV 2.3, I am having trouble assigning values to a Mat array (or say image) inside a loop. Here is the code snippet which I am using; int paddedHeight = 256 + 2*padSize; int paddedWidth = 256 + 2*padSize; int n = 266; // padded height or width cv::Mat fx = cv::Mat(paddedHeight,paddedWidth,CV_64FC1); cv::Mat fy = cv::Mat(paddedHeight,paddedWidth,CV_64FC1); float value = -n/2.0f; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) fx.at<cv::Vec2d>(i,j) = value++; value = -n/2

Is sequence unpacking atomic?

一曲冷凌霜 提交于 2019-12-23 10:13:12
问题 Is sequence unpacking atomic? e.g.: (a, b) = (c, d) I'm under the impression it is not. Edit: I meant atomicity in the context of multi-threading, i.e. whether the entire statement is indivisible, as atoms used to be. 回答1: It is one operation; the right-hand expression is evaluated before the left-hand assignment is applied: >>> a, b = 10, 20 >>> a, b (10, 20) >>> b, a = a, b >>> a, b (20, 10) >>> a, b = a*b, a/b >>> a, b (200, 2) Or, if you are talking about multi-threaded environments, then

Weird lambda behaviour in loops [duplicate]

浪子不回头ぞ 提交于 2019-12-23 09:30:08
问题 This question already has answers here : Local variables in nested functions (3 answers) Closed 6 years ago . I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code: from functools import partial if __name__ == '__main__': sequence = ['foo', 'bar', 'spam'] loop_one = lambda seq: [lambda: el for el in seq] no_op = lambda x: x loop_two = lambda seq: [partial(no_op, el) for el in seq] for func in (loop_one, loop_two): print [f() for f in

c++ default assignment operator

人走茶凉 提交于 2019-12-23 09:05:49
问题 int a[10]; int b[10]; a = b; // struct test { int a[10]; }; test a,b; a = b; First code doesn't compile, since we cant assign array, but the second does. Isn't the default assignment operator of class simply call assignment for each data members? Why does the the second code compile? 回答1: From the C++11 draft, section 12.8: The implicitly-defined copy/move assignment operator for a non-union class X performs memberwise copy/move assignment of its subobjects. The direct base classes of X are

Assigning the value of an array to a variable bash script

元气小坏坏 提交于 2019-12-23 04:40:11
问题 I want to ask about the syntax i use to assign a value of a two dimensional array element to a variable. this is basically what i am trying to do: I have a 2 dimensional array of characters and a string called sub_string that gets the value of a particular element in the array and put it in another string called whole_string for ((j=1;j<=num_columns;j++)) do for ((i=1;i<=num_rows;i++)) do Assigning the value of the element [i,j] in the array matrix to a sub string whole_string="$whole_String

Fortran syntax for assignments

微笑、不失礼 提交于 2019-12-23 03:56:35
问题 The Fortran syntax is driving me mad! Can anyone explain how I can call the assignment (I'm pretty sure that is not the right terminology either...). I'm trying to assign a type according to the value type . I have the following: module test_module implicit none type :: mytype integer :: i real :: r logical :: l contains generic :: assignment(=) => mytype_to_type procedure, pass(me) :: mytype_to_type end type mytype contains subroutine mytype_to_type(t, me) implicit none class(*), intent

Assigning an address to a struct pointer array member in C

柔情痞子 提交于 2019-12-22 17:48:36
问题 Having considerable trouble with some pointer arithmatic. I think I get the concepts (pointer variables point to a memory address, normal variables point to data) but I believe my problem is with the syntax ( *, &, (*), *(), etc.) What I want to do is build dynamic arrays of a custom struct (i.e. arrays of pointers to heap structs), and my interface provides two methods, "ad_to_obj_array" (which takes the object to add and the array which can be null for empty) and "obj_array_dustbin" (which

how to make copy of array instead of reference in java? [duplicate]

左心房为你撑大大i 提交于 2019-12-22 09:49:09
问题 This question already has answers here : How do I do a deep copy of a 2d array in Java? (6 answers) Closed 6 years ago . I want to make an exact copy of given array to some other array but such that even though I change the value of any in the new array it does not change the value in the original array. I tried the following code but after the third line both the array changes and attains the same value. int [][]a = new int[][]{{1,2},{3,4},{5,6}}; int[][] b = a; b[1][0] = 7; instead of the

make an object behave like an Array for parallel assignment in ruby

痞子三分冷 提交于 2019-12-22 07:25:50
问题 Suppose you do this in Ruby: ar = [1, 2] x, y = ar Then, x == 1 and y == 2. Is there a method I can define in my own classes that will produce the same effect? e.g. rb = AllYourCode.new x, y = rb So far, all I've been able to do with an assignment like this is to make x == rb and y = nil. Python has a feature like this: >>> class Foo: ... def __iter__(self): ... return iter([1,2]) ... >>> x, y = Foo() >>> x 1 >>> y 2 回答1: Yep. Define #to_ary . This will let your object be treated as an array

updating references in an expression with a nested assignment

坚强是说给别人听的谎言 提交于 2019-12-22 04:15:11
问题 Looking at this example code similar to this question: public class A { public static void main(String args[]){ A a = new A(); System.out.println(a.equals((a = null))); } } This prints false. Why doesn't it fail with a NullPointerException? The assignment has to get processed before the equals method can run, but somehow that doesn't affect the reference that equals is called on until after the whole line is evaluated? I didn't see where in the Java language spec it describes this, did I miss