array

What is the difference between contiguous and non-contiguous arrays?

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In the numpy manual about the reshape() function, it says >>> a = np.zeros((10, 2)) # A transpose make the array non-contiguous >>> b = a.T # Taking a view makes it possible to modify the shape without modifying the # initial object. >>> c = b.view() >>> c.shape = (20) AttributeError: incompatible shape for a non-contiguous array My questions are: What are continuous and noncontiguous arrays? Is it similar to the contiguous memory block in C like What is a contiguous memory block? Is there any performance difference between these two? When

sklearn DeprecationWarning truth value of an array

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Running a rasa_core example from the docs with and get this error output after each message in the dialog: .../sklearn/...: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty. It's an issue with numpy that has been fixed but not been published in the latest release: https://github.com/scikit-learn/scikit-learn/issues/10449 The following has not worked to temporarily silence the warning: Adding -W ignore

Convert Any type in scala to Array[Byte] and back

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following question: I have a variable value in my program which is declared as Any value. I want to convert this value to Byte Array.. How can I serialize to byte Array and back? I found examples related to other types such as Double or Int, but not as Any. 回答1: This should do what you need. It's pretty similar to how one would do it in Java. import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream} object Serialization extends App { def serialise(value: Any): Array[Byte] = { val stream:

Determine if more than half of the array repeats in a distinct array

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I was looking at the following question from Glassdoor : Given N credits cards, determine if more than half of them belong to the same person/owner. All you have is an array of the credit card numbers, and an api call like isSamePerson(num1, num2). It is clear how to do it in O(n^2) but some commenters said it can be done in O(n) time. Is it even possible? I mean, if we have an array of credit card numbers where some numbers are repeated, then the claim makes sense. However, we need to make an API call for each credit card number to see its

Which is faster / more efficient - lots of little MySQL queries or one big PHP array?

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a PHP/MySQL based web application which has multiple language support by way of a MySQL table "language_strings" with string_id, lang_id, lang_text fields. I then call the following function when I need to display a string in the selected language... public function get_lang_string($string_id,$lang_id) { $db=new Database(); $sql=sprintf("SELECT lang_string FROM language_strings WHERE lang_id IN (1, %s) AND string_id=%s ORDER BY lang_id DESC LIMIT 1", $db->escape($lang_id, "int"), $db->escape($string_id,"int")); $row=$db->query_first(

How do I store an array in a file to access as an array later with PHP?

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I just want to quickly store an array which I get from a remote API, so that i can mess around with it on a local host. So: I currently have an array. I want to people to use the array without having to get it from the API. There are no needs for efficiency etc here, this isnt for an actual site just for getting some sanitizing/formatting methods made etc Is there a function like store_array() or restore_arrray() ?! 回答1: The best way to do this is JSON serializing. It is human readable and you'll get better performance (file is smaller and

Finding even numbers in an array

匿名 (未验证) 提交于 2019-12-03 02:51:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given an array of length n containing at most e even numbers and a function isEven that returns true if the input is even and false otherwise, write a function that prints all the even numbers in the array using the fewest number of calls to isEven. The only thing I could think was to do a linear search and stop after I hit the end of the array or found e even numbers. Can someone please tell me a better way? 回答1: You can do a binary search instead. Write a function that does the following: Start with A = array and n = length(A) . While n>1

How to Validate FormArray length in angular2

匿名 (未验证) 提交于 2019-12-03 02:51:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a data driven form in angular2 like below this.formBuilder.group({ 'name': ['',Validators.required], 'description': ['', Validators.required], 'places': this.formBuilder.array([], Validators.minlength(1)) }) I want to add validations to the place formArray, so i am adding minlength validation, but minlength validation is not working on formArray. What are the other validations for formArray, so that form must be valid only when places array contain atleast one place. 回答1: Add this custom validator to your validation service:

scipy.optimize.curvefit() - array must not contain infs or NaNs

匿名 (未验证) 提交于 2019-12-03 02:51:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to fit some data to a curve in Python using scipy.optimize.curve_fit . I am running into the error ValueError: array must not contain infs or NaNs . I don't believe either my x or y data contain infs or NaNs: >>> x_array = np.asarray_chkfinite(x_array) >>> y_array = np.asarray_chkfinite(y_array) >>> To give some idea of what my x_array and y_array look like at either end ( x_array is counts and y_array is quantiles): >>> type(x_array) <type 'numpy.ndarray'> >>> type(y_array) <type 'numpy.ndarray'> >>> x_array[:5] array([0, 0, 0,

How do I multiply each member of an array by a scalar in javascript?

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: For example, how do I achieve the following without iterating over the array ? var a = [1, 2, 3] * 5; // a should equal [5, 10, 15] 回答1: Array.map() is available to IE users as of IE9, so if you don't care about compatibility at all you can use this: var a = [1, 2, 3].map(function(x) { return x * 5; }); For JavaScript 1.8, this is as short as you can go: var a = [1, 2, 3].map(function(x) x * 5); If you need maximal browser compatibility, you'll have to put up with a loop. Either way you'll be iterating over the array; Array.map() just makes