array

Fitting a 3D array of data to a 1D function with numpy or scipy

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 4I am currently trying to fit a lot of data to a sine function. In the case where I only have one set of data (1D array), scipy.optimize.curve_fit() works fine. However it does not permit a higher dimensional data input if the function itself is only one dimensional as far as i can see. I don't want to iterate over the array using for loops as that works incredibly slow in python. My code so far should look similar to this: from scipy import optimize import numpy as np def f(x,p1,p2,p3,p4): return p1 + p2*np.sin(2*np.pi*p3*x + p4) #fit

How do I quicky fill an array with a specific value?

匿名 (未验证) 提交于 2019-12-03 02:15:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Array.Clear() fills the arrays with the default value (zero for integers), I would like to fill it using -1 for example. Thanks. 回答1: The other way is: int[] arr = Enumerable.Repeat(-1, 10).ToArray(); Console.WriteLine(string.Join(",",arr)); 回答2: I am not aware of such a method. You could write one yourself, though: public static void Init<T>(this T[] array, T value) { for(int i=0; i < array.Length; ++i) { array[i] = value; } } You can call it like this: int[] myArray = new int[5]; myArray.Init(-1); 文章来源: How do I quicky fill an array with a

node - invalid array length

匿名 (未验证) 提交于 2019-12-03 02:15:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using node v0.12.4. When I run the following code with node --max-old-space-size=8192 test.js it gives me the error FATAL ERROR: invalid array length Allocation failed - process out of memory var a = new Array(200000000); console.log(a.length); However if I change the size to 300000000 I don't get any error. What's going on here? Is there some command line argument aside from --max-old-space-size I need to change? 回答1: V8's heap size is limited to 1 GB for 64 bit and 512 for 32-bit machine, but Buffer objects exist largely outside the

how to return numpy.array from boost::python?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to return some data from c++ code as a numpy.array object. I had a look at boost::python::numeric , but its documentation is very terse. Can I get an example of e.g. returning a (not very large) vector to python? I don't mind doing copies of data. 回答1: Another interface between Boost.Python and NumPy can be found here: https://github.com/ndarray/Boost.NumPy It's a moderately complete wrapper of the NumPy C-API into a Boost.Python interface, with the intention of eventually submitting it to Boost. I'm not sure the documentation

Finding the median of an unsorted array

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: To find the median of an unsorted array, we can make a min-heap in O(nlogn) time for n elements, and then we can extract one by one n/2 elements to get the median. But this approach would take O(nlogn) time. Can we do the same by some method in O(n) time? If we can, then please tell or suggest some method. 回答1: You can use the Median of Medians algorithm to find median of an unsorted array in linear time. 回答2: I have already upvoted the @dasblinkenlight answer since the Median of Medians algorithm in fact solves this problem in O(n

In Javascript, how do I check if an array has duplicate values? [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Possible Duplicate: Easiest way to find duplicate values in a javascript array How do I check if an array has duplicate values? If some elements in the array are the same, then return true. Otherwise, return false. ['hello','goodbye','hey'] //return false because no duplicates exist ['hello','goodbye','hello'] // return true because duplicates exist 回答1: If you have an ES2015 environment (as of this writing: io.js, IE11, Chrome, Firefox, WebKit nightly), then the following will work, and will be fast (viz. O(n)): function hasDuplicates(array

Selecting multiple slices from a numpy array at once

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm looking for a way to select multiple slices from a numpy array at once. Say we have a 1D data array and want to extract three portions of it like below: data_extractions = [] for start_index in range(0, 3): data_extractions.append(data[start_index: start_index + 5]) Afterwards data_extractions will be: data_extractions = [ data[0:5], data[1:6], data[2:7] ] Is there any way to perform above operation without the for loop? Some sort of indexing scheme in numpy that would let me select multiple slices from an array and return them as that

how to loop through json array in jquery?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a php page from which I get response in json: [{'com':'something'},{'com':'some other thing'}] I want to loop it and append each to a div. This is what I tried: var obj = jQuery.parseJSON(response); $.each(obj.com, function(key,value) { alert(key+':'+value); } This alerts as undefined , and also response is the json array.. Please help. 回答1: Your array has default keys(0,1) which store object {'com':'some thing'} use: var obj = jQuery.parseJSON(response); $.each(obj, function(key,value) { alert(value.com); }); 回答2: Try this: var data

How can I pass an array of PDO parameters yet still specify their types?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: $sql = "SELECT * FROM table WHERE id LIKE CONCAT('%', :id, '%') LIMIT :limit1, :limit2"; I want to still use the array input like this: $stmt->execute($array); Otherwise I cannot reuse the same method for executing my queries. At the same time, the :limit1 and :limit2 doesn't work unless it is put in like this: $stmt->bindParam(':limit1', $limit1, PDO::PARAM_INT); I tried to do both but it doesn't execute with the bindParams: $stmt->bindParam(':limit2', $limit2, PDO::PARAM_INT); $stmt->execute($array); What is the way around it? I thought I

How to do sparse array in Cocoa

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an undetermined size for a dataset based on unique integer keys. I would like to use an NSMutableArray for fast lookup since all my keys are integer based. I want to do this. NSMutableArray* data = [NSMutableArray array]; // just create with 0 size then later people will start throwing data at me with integer indexes (all unique) so I just want to do something like this... if ([data count] < index) [data resize:index]; // ? how do you resize and have the array resized so that i can then do... [data insertObject:obj atIndex:index];