array

Convert 2D array to std::map?

匿名 (未验证) 提交于 2019-12-03 08:50:26
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: An array can be converted into a std::vector easily and efficiently: template < typename T , int N > vector < T > array_to_vector ( T (& a )[ N ]) { return vector < T >( a , a + sizeof ( a ) / sizeof ( T )); } Is there a similar way to convert a two dimensional array into a std::map without iterating over the members? This looks like an unusual function signature, but in my particular situation, the keys and values in these maps will be of the same type. template < typename T , int N > map < T , T > array_to_map ( T (& a )[ N ][ 2

How to generate multiple check boxes in symfony2 form

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to display checkboxes from a pre-defined array in my Symfony form. User should be able to select more than one but I am not able to do it. This is my code: public function buildForm(FormBuilder $builder, array $options) { $roles = array('role1', 'role2', 'role3'); $builder ->add('name') ->add('roles', 'checkbox', $roles) ; } 回答1: See the choice type reference . public function buildForm(FormBuilder $builder, array $options) { $roles = ['role1', 'role2', 'role3']; $builder ->add('name') ->add('roles', 'choice', [ 'choices' => $roles,

Calculating cron next-run-time in PHP

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm designing a task scheduler in my own personal framework and am trying to avoid the not-as-flexible "run every n minutes/hours/days" method that'd be easier to implement. What I'd like to do is mimic cron scheduling. I've got functions in place to split patterns and calculate the next value for the next date (day of month) currently, but don't want to keep pushing forward if there's something easier than what I'm doing, or possibly a better way to do what I'm trying to do. /** * Takes pattern(s) for various time attributes and calculates

Creating array of pointers to class object

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Question: Create an array of at least four pointers to Reader objects. Use the New operator to create at least four pointers to derived class objects and assign them to the array. I'm not sure If I did it right or not. Reader is the base class. John, David, Daniel, Mark are the derived class int main ( void ) { Reader * obj [ 4 ]; obj [ 0 ] = new John (); obj [ 1 ] = new David (); obj [ 3 ] = new Daniel (); obj [ 2 ] = new Mark (); } Would this be right??? 回答1: Your code is correct . And as @sharptooth suggested, make a practice of

Remove JSON object from JSONArray - Jettison

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a direct way to remove an JSONObject stored in the JSONArray by using index. I tried all the possibilities. Still not able to remove the JSON object from the JSON Array. Any hint will be helpful Thanks 回答1: In java-json , there is no direct method to remove jsonObject, but using json-simple , it is simple to do so: JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); JSONObject jsonObject1 = new JSONObject(); JSONObject jsonObject2 = new JSONObject(); jsonObject.put("key1", "value1"); jsonObject1.put(

Plotting a 2D Array with Matplotlib

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I have a 2D array (named Data) that looks like: Shape 0 Shape 1 ... Shape N ------- ------- ------- Scale 0 | Value00 , Value01 ... Value0N | Scale 1 | Value10 , Value11 ... Value1N | . . . Scale N | ValueN0 , ValueN1 ... ValueNN | And I want to create a 3D plot where the ValueXXs are the Z axis. I've tried two attempts, but each give me a surface that is rotated with respect to the other one, so I've gotten myself a bit confused. Here is my 1st attempt at a solution: x,y = numpy.mgrid[0:50:50j,0:50:50j] f = Data fig = plt.figure() ax =

Boost.Python - Vector to Numpy Array

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following class: class PyWav { public: static inline boost::python::object sdVecToNumpyArray(std::vector<double> const& vec) { npy_intp size = vec.size(); double * data = size ? const_cast<double *>(&vec[0]) : static_cast<double *>(NULL); PyObject * pyObj = PyArray_SimpleNewFromData(1, &size, NPY_DOUBLE, data); boost::python::handle<> handle ( pyObj ); boost::python::numeric::array arr(handle); return arr.copy(); } // Access function inline boost::python::numeric::array toNumPy() { std::vector<double> v = Signal(); // get the

3D array -&gt; apply -&gt; 3D array

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: It seems apply will not re-assemble 3D arrays when operating on just one margin. Consider: arr <- array( runif(2*4*3), dim=c(2, 4, 3), dimnames=list(a=paste0("a", 1:2), b=paste0("b", 1:4), c=paste0("c", 1:3)) ) # , , c = c1 # # b # a b1 b2 b3 b4 # a1 0.7321399 0.8851802 0.2469866 0.9307044 # a2 0.5896138 0.6183046 0.7732842 0.6652637 # # , , c = c2 # b # a b1 b2 b3 b4 # a1 0.5894680 0.7839048 0.3854357 0.56555024 # a2 0.6158995 0.6530224 0.8401427 0.04044974 # # , , c = c3 # b # a b1 b2 b3 b4 # a1 0.3500653 0.7052743 0.42487635 0.5689287 #

AWK Error: Attempt to use array in a scalar context

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am learning AWK. Here is a simple code snippet I tried to split a string into an array and iterate through it. BEGIN { split("a,b,c", a, ","); for(i = 1; i <= length(a); i++) { print a[i]; } } On running this code, I get the following error: awk: awk.txt:4: fatal: attempt to use array `a' in a scalar context However, if I change the for statement to for (i in a) it works just fine. On further trying to understand what this means by Googling it, I see a number of forums (eg: [1] ) talking about awk bugs . It will be great if AWK gurus here

Behavior of 'subsref' for arrays of objects

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Imagine a simple array of structures, say: A = struct ( 'x' , { 1 2 3 }, 'y' , { 'a' 'b' 'c' }); Asking for a given property for all this array's elements will give something like: >> A . x ans = 1 ans = 2 ans = 3 Now, if I explicitly call the subsref function directly on this array, it only retrieves the first element's property: >> builtin ( 'subsref' , A , substruct ( '.' , 'x' )) ans = 1 Why? And is there a possibility to call explicitly another built-in method that will retrieve the property for all the array's elements? 回答1: