array

Append a NumPy array to a NumPy array

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a numpy_array. Something like [ a b c ] . And then I want to append it into another NumPy array (just like we create a list of lists). How do we create an array of NumPy arrays containing NumPy arrays? I tried to do the following without any luck >>> M = np . array ([]) >>> M array ([], dtype = float64 ) >>> M . append ( a , axis = 0 ) Traceback ( most recent call last ): File " " , line 1 , in AttributeError : 'numpy.ndarray' object has no attribute 'append' >>> a array ([ 1 , 2 , 3 ]) 回答1: In [ 1 ]: import numpy as np In [

What is the maximum size of an array in PHP?

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: We like to store database values in array. But we do not know the maximum size of an array which is allowed in PHP? 回答1: There is no max on the limit of an array. There is a limit on the amount of memory your script can use. This can be changed in the 'memory_limit' in your php.ini configuration. 回答2: Array size is limited only by amount of memory your server has. If your array gets too big, you will get "out of memory" error. 文章来源: What is the maximum size of an array in PHP?

Scala generic method - No ClassTag available for T

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm relatively new to Scala and am trying to define a generic object method. However, when I refer to the parameterized type within the method I am getting "No ClassTag available for T". Here is a contrived example that illustrates the problem. scala> def foo[T](count: Int, value: T): Array[T] = Array.fill[T](count)(value) <console>:7: error: No ClassTag available for T def foo[T](count: Int, value: T): Array[T] = Array.fill[T](count)(value) ^ Thanks in advance for help in understanding what is wrong here and how to make this contrived

Arrays in unix shell?

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I create an array in unix shell scripting? 回答1: The following code creates and prints an array of strings in shell: #!/bin/bash array=( "A" "B" "ElementC" "ElementE" ) for element in ${array[@]} do echo $element done echo "" echo "Nbr of elements:" ${#array[@]} echo "" echo ${array[@]} Result: A B ElementC ElementE Nbr of elements: 4 A B ElementC ElementE 回答2: in bash, you create array like this arr=(one two three) to call the elements $ echo ${arr[0]} one $ echo ${arr[2]} three to ask for user input, you can use read read -p "Enter

how to convert array values from string to int?

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: $string = "1,2,3" $ids = explode(',', $string); var_dump($ids); returns array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } I need for the values to be of type int instead of type string. Is there a better way of doing this than looping through the array with a foreach and converting each string to int? 回答1: $integerIDs = array_map('intval', explode(',', $string)); 回答2: This is almost 3 times faster than explode() , array_map() and intval() : $integerIDs = json_decode('[' . $string . ']', true); 回答3: So I was curious

How to debug a bash script?

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there any way to debug a bash script? E.g something that prints a sort of execution log like "calling line 1", "calling line 2" etc. 回答1: sh -x script [arg1 ...] bash -x script [arg1 ...] These give you a trace of what is being executed. (See also 'Clarification' near the bottom of the answer.) Sometimes, you need to control the debugging within the script. In that case, as Cheeto reminded me, you can use: set -x This turns debugging on. You can then turn it off again with: set +x (You can find out the current tracing state by analyzing $

PHP Optional Parameters - specify parameter value by name?

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I know it is possible to use optional arguments as follows: function doSomething($do, $something = "something") { } doSomething("do"); doSomething("do", "nothing"); But suppose you have the following situation: function doSomething($do, $something = "something", $or = "or", $nothing = "nothing") { } doSomething("do", $or=>"and", $nothing=>"something"); So in the above line it would default $something to "something", even though I am setting values for everything else. I know this is possible in .net - I use it all the time. But I need to do

Powershell Multidimensional Arrays

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a way of doing Arrays in other languagues like this: $x = "David" $arr = @() $arr[$x]["TSHIRTS"]["SIZE"] = "M" This generates an error. 回答1: You are trying to create an associative array (hash). Try out the following sequence of commands $arr=@{} $arr["david"] = @{} $arr["david"]["TSHIRTS"] = @{} $arr["david"]["TSHIRTS"]["SIZE"] ="M" $arr.david.tshirts.size Note the difference between hashes and arrays $a = @{} # hash $a = @() # array Arrays can only have non-negative integers as indexes 回答2: from powershell.com: PowerShell supports

How to extend an array in-place in Numpy?

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Currently, I have some code like this import numpy as np ret = np . array ([]) for i in range ( 100000 ): tmp = get_input ( i ) ret = np . append ( ret , np . zeros ( len ( tmp ))) ret = np . append ( ret , np . ones ( fixed_length )) I think this code is not efficient as np.append needs to return a copy of the array instead of modify the ret in-place I was wondering whether I can use the extend for a numpy array like this: import numpy as np from somewhere import np_extend ret = np . array ([]) for i in range ( 100000 ): tmp = get

ArrayBuffer to base64 encoded string

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I need an efficient (read native) way to convert an ArrayBuffer to a base64 string which needs to be used on a multipart post. 回答1: function _arrayBufferToBase64 ( buffer ) { var binary = '' ; var bytes = new Uint8Array ( buffer ); var len = bytes . byteLength ; for ( var i = 0 ; i but, non-native implementations are faster e.g. https://gist.github.com/958841 see http://jsperf.com/encoding-xhr-image-data/6 回答2: This works fine for me: var base64String = btoa ( String . fromCharCode . apply ( null , new Uint8Array ( arrayBuffer )));