array

Deserializing an empty array using Json.NET

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a C# application that uses Json.NET v7.0.1. As a result of a REST call, I get back some JSON in the form of: { "messages": [ {"phoneNumber":"123-456-7890", "smsText":"abcd1234="}, {"phoneNumber":"234-567-8901", "smsText":"efgh5678="}, {"phoneNumber":"345-678-9012", "smsText":"12345asdf"} ] } If there is no message data to return, the JSON that I get back looks like this: { "messages": [ ] } My Message class looks like this: public class Message { public string PhoneNumber { get; set; } public string SmsText { get; set; } public

.toArray(new MyClass[0]) or .toArray(new MyClass[myList.size()])?

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Assuming I have an ArrayList ArrayList myList; And I want to call toArray, is there a performance reason to use MyClass[] arr = myList.toArray(new MyClass[myList.size()]); over MyClass[] arr = myList.toArray(new MyClass[0]); ? I prefer the second style, since it's less verbose, and I assumed that the compiler will make sure the empty array doesn't really get created, but I've been wondering if that's true. Of course, in 99% of the cases it doesn't make a difference one way or the other, but I'd like to keep a consistent style between my

Angular 2: How would you display an array as a series of Key/Value pairs?

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm pulling in JSON data from an external data source and part of the payload is an array that needs to be displayed as a series of key/value pairs. I realize one way would be to transform the array into an interface/object via Typescript but in my case the data needs to be transformed declaratively in the Angular template's html markup. So, given some data in the form of: heroes = ['Hurricane', 12, 'Wolf', 42, 'Zephyr', 28] Displaying the data via *ngFor: <div *ngFor="let hero of heroes"> {{hero}} </div> would render: Hurricane 12 Wolf 42

MongoDB nested array query

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've asked this as a comment on another question, and also posted a question on mongodb-user. No responses so far, so I'm resorting to asking a separate question. The documentation states: If the field holds an array, then the $in operator selects the documents whose field holds an array that contains at least one element that matches a value in the specified array (e.g. , , etc.) I'm using: mongod --version: db version v2.2.2, pdfile version 4.5 Thu May 30 12:19:12 git version: d1b43b61a5308c4ad0679d34b262c5af9d664267 mongo --version:

ValueError: setting an array element with a sequence. scipy minimize [closed]

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: """ ___ """ from scipy.optimize import minimize import numpy as np LENGTH = 100 def process(x): return x * 2 + 5 def draw(process, length): """ """ y = np.random.normal(0, 10, length) data = [process(y_) for y_ in y] rnd = np.random.normal(3, 1, len(data)) return y, rnd + data def maximum_likelyhood(y, X): objective = lambda b: np.transpose(X) * (y - X * b) x0 = np.zeros(100) res = minimize(objective, x0=x0) return res.x y, X = draw(process, LENGTH) print maximum_likelyhood(y, X) produces a ValueError: setting an array element with a

cakephp sum() on single field

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have searched high and low on how to just get a total of a field called points. I just need one total figure but the best I can get is a list of records from the Points table with the associated records from the Members. $totalPoints = $this->Member->Point->find('all', array( array('fields' => array('sum(Point.points) AS Point.ctotal')))); 回答1: Why not using virtualFields as documented and suggested by the docs? http://book.cakephp.org/2.0/en/models/virtual-fields.html $this->Member->Point->virtualFields['total'] = 'SUM(Point.points)';

Python scipy.optimize.fmin_l_bfgs_b error occurs

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My code is to implement an active learning algorithm, using L-BFGS optimization. I want to optimize four parameters: alpha , beta , w and gamma . However, when I run the code below, I got an error: optimLogitLBFGS = sp.optimize.fmin_l_bfgs_b(func, x0 = x0, args = (X,Y,Z), fprime = func_grad) File "C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py", line 188, in fmin_l_bfgs_b **opts) File "C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py", line 311, in _minimize_lbfgsb isave, dsave) _lbfgsb.error: failed in converting 7th argument

Swift converting signed array of Int [int8] to unsigned array of Int [UInt8]

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to convert signed array of [Int8] to unsigned array of [UInt8]. let arryData: [Int8] = [-108, 11, -107, -14, 35, -57, -116, 118, 54, 91, 12, 67, 21, 29, -44, 111] I just want to convert this above into array of Unsigned [UInt8]. How to achieve this in swift.? Thanks in advance. 回答1: If your intention is to convert signed 8-bit integers to unsigned ones with the same bit representation (e.g. -1 -> 255 ): let intArray: [Int8] = [0, 1, 2, 127, -1, -2, -128] let uintArray = intArray.map { UInt8(bitPattern: $0) } print(uintArray) // [0, 1, 2,

How to initialize the dynamic array of chars with a string literal in C++?

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to do the following: std::unique_ptr<char[]> buffer = new char[ /* ... */ ] { "/tmp/file-XXXXXX" }; Obviously, it doesn't work because I haven't specified the size of a new array. What is an appropriate way to achieve my goal without counting symbols in a string literal? Usage of std::array is also welcome. Update #1: even if I put the size of array, it won't work either. Update #2: it's vital to have a non-const access to the array as a simple char* pointer. 回答1: Here's a solution based on std::array : std::array<char, sizeof("/tmp

“Array Subscript is not an integer” c

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to do matrix multiplication using for loops and I am getting an error, "Array Subscript is not an integer" Could I get some help please. #include <stdio.h> #include <stdlib.h> int main(void) { float Matrix_1[3][3] = {{3.4, 4.4, 1.2},{5.3, 5.7, 2.2},{6.2, -2.4, 0.9}}; float Matrix_2[3][3] = {{7.3, 4.9, 3.7},{-2.4, 4.9, -10.2},{7.3, 5.2, 1.7}}; float i, j, k; float result[3][3]; for (i = 0; i < 1; i++) { for (j = 0; j < 3; j++) { for(k = 0; k < 3; k++) { result = result + Matrix_1[i][k] * Matrix_2[k][j]; } } } printf("The result of