array

Destination Array not long enough?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a class with the following method: public List<Bike> bikesCopy { get { List<Bike> bs; lock (_bikes) bs = new List<Bike>(_bikes); return bs; } } Which makes a copy of another list, private List<Bike> _bikes; The strange thing now is, that I get the following error: Destination array was not long enough. Check destIndex and length, and the array's lower bounds. What is the problem here? 回答1: I would say the error lies in the object _bikes not being thread safe. As commented, somewhere there is a modify of the _bikes object that is not

Checking if an object is a given type in Swift

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an array that is made up of AnyObject . I want to iterate over it, and find all elements that are array instances. How can I check if an object is of a given type in Swift? 回答1: If you want to check against a specific type you can do the following: if let stringArray = obj as? [String] { // obj is a string array. Do something with stringArray } else { // obj is not a string array } You can use "as!" and that will throw a runtime error if obj is not of type [String] let stringArray = obj as! [String] You can also check one element at a

how to strip punctuation in php

匿名 (未验证) 提交于 2019-12-03 02:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I strip punctuation except for these characters . = $ ' - % 回答1: Since you need to match some Unicode characters ( ) it would be sensible to use a regular expression. The pattern \p{P} matches any known punctuation, and the assertion excludes your desired special characters from vanishing: 回答2: Here's a neat way to do it: preg_replace("#[[:punct:]]#", "", $target); 回答3: <? $whatToStrip = array("?","!",",",";"); // Add what you want to strip in this array $test = "Hi! Am I here?"; echo $test."\n\n"; echo str_replace($whatToStrip, "",

Efficient data structure for fast random access, search, insertion and deletion

匿名 (未验证) 提交于 2019-12-03 02:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm looking for a data structure (or structures) that would allow me keep me an ordered list of integers, no duplicates, with indexes and values in the same range. I need four main operations to be efficient, in rough order of importance: taking the value from a given index finding the index of a given value inserting a value at a given index deleting a value at a given index Using an array I have 1 at O(1), but 2 is O(N) and insertion and deletions are expensive (O(N) as well, I believe). A Linked List has O(1) insertion and deletion (once

Convert NumPy array to cvMat cv2

匿名 (未验证) 提交于 2019-12-03 02:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: With OpenCV 2, IPython now uses NumPy arrays by default. cvimage = cv2.imread("image.png") #using OpenCV 2 type(cvimage) Out: numpy.ndarray #dtype is uint8 pltimage = plt.imread("image.png") #using Matplotlib type(pltimage) Out: numpy.ndarray #dtype is float plt.imshow(cvimage) # works great cv2.imshow(cvimage) TypeError: Required argument 'mat' (pos 2) not found Since cv2 uses NumPy arrays by default, there is no longer any cv::Mat constructor and NumPy has no functions to convert to a cv::Mat array. Any ideas? 回答1: The function has the

Convert string with commas to array

匿名 (未验证) 提交于 2019-12-03 02:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I convert a string to a JavaScript array? Look at the code: var string = "0,1"; var array = [string]; alert(array[0]); In this case, alert would pop-up a 0,1 . When it would be an array, it would pop-up a 0 , and when alert(array[1]); is called, it should pop-up the 1 . Is there any chance to convert such string into a JavaScript array? 回答1: For simple array members like that, you can use JSON.parse . var array = JSON.parse("[" + string + "]"); This gives you an Array of numbers. [0, 1] If you use .split() , you'll end up with an

Can I append an array to &#039;formdata&#039; in javascript?

匿名 (未验证) 提交于 2019-12-03 02:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using FormData to upload files. I also want to send an array of other data. When I send just the image, it works fine. When I append some text to the formdata, it works fine. When I try to attach the 'tags' array below, everything else works fine but no array is sent. Any known issues with FormData and appending arrays? Instantiate formData: formdata = new FormData(); The array I create. Console.log shows everything working fine. // Get the tags tags = new Array(); $('.tag-form').each(function(i){ article = $(this).find('input[name=

Binary data with pyserial(python serial port)

匿名 (未验证) 提交于 2019-12-03 02:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: serial.write() method in pyserial seems to only send string data. I have arrays like [0xc0,0x04,0x00] and want to be able to send/receive them via the serial port? Are there any separate methods for raw I/O? I think I might need to change the arrays to ['\xc0','\x04','\x00'], still, null character might pose a problem. 回答1: You need to convert your data to a string "\xc0\x04\x00" Null characters are not a problem in Python -- strings are not null-terminated the zero byte behaves just like another byte "\x00" . One way to do this: >>> import

D3.js: Get an array of the data attached to a selection?

匿名 (未验证) 提交于 2019-12-03 02:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'd like to get an array of all the data attached to a selection in D3. I'm working with the example from the General Update pattern , and trying this: var text = svg.selectAll("text") .data(data, function(d) { return d; }); var textEnter = text.enter().append("text") .attr("class", "enter") .text(function(d) { return d; }); console.log('textEnter data', textEnter[0]); var textEnterKeys = d3.map(textEnter[0], function(d) { return d.__data__; }); console.log('textEnterKeys', textEnterKeys); But textEnterKeys just looks exactly the same as

C# lambda expressions and IComparer

匿名 (未验证) 提交于 2019-12-03 02:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using lambda expressions to sort and search an array in C#. I don't want to implement the IComparer interface in my class, because I need to sort and search on multiple member fields. class Widget { public int foo; public void Bar() { Widget[] widgets; Array.Sort(widgets, (a, b) => a.foo.CompareTo(b.foo)); Widget x = new Widget(); x.foo = 5; int index = Array.BinarySearch(widgets, x, (a, b) => a.foo.CompareTo(b.foo)); } } While the sort works fine, the binary search gives a compilation error Cannot convert lambda expression to type