array

Can we convert a byte array into an InputStream in Java?

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can we convert a byte array into an InputStream in Java? I have been looking on the internet but couldn't find it. I have a method that has an InputStream as argument. The InputStream cph I have is base64 encoded so I had to decode it using BASE64Decoder decoder = new BASE64Decoder(); byte[] decodedBytes = decoder.decodeBuffer(cph); Now how do I convert decodedBytes again to InputStream ? 回答1: Use ByteArrayInputStream : InputStream is = new ByteArrayInputStream(decodedBytes); 回答2: If you use Robert Harder's Base64 utility , then you can do:

In Python NumPy what is a dimension and axis?

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am coding with Pythons NumPy module. If coordinates of a point in 3D space are described as [1, 2, 1] , wouldn't that be three dimensions, three axis, a rank of three? Or if that is one dimension then shouldn't it be points (plural), not point? Here is the documentation: In Numpy dimensions are called axes. The number of axes is rank. For example, the coordinates of a point in 3D space [1, 2, 1] is an array of rank 1, because it has one axis. That axis has a length of 3. Source: http://wiki.scipy.org/Tentative_NumPy_Tutorial 回答1: In numpy

How can I shuffle an array? [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Possible Duplicate: How to randomize a javascript array? I want to shuffle an array of elements in JavaScript like these: [ 0 , 3 , 3 ] -> [ 3 , 0 , 3 ] [ 9 , 3 , 6 , 0 , 6 ] -> [ 0 , 3 , 6 , 9 , 6 ] [ 3 , 3 , 6 , 0 , 6 ] -> [ 0 , 3 , 6 , 3 , 6 ] 回答1: Use : /** * Shuffles array in place. * @param {Array} a items An array containing the items. */ function shuffle ( a ) { var j , x , i ; for ( i = a . length - 1 ; i > 0 ; i --) { j = Math . floor ( Math . random () * ( i + 1 )); x = a [ i ]; a [ i ] = a [ j ]; a [ j ] = x ; } }

PHP: Warning: sort() expects parameter 1 to be array, resource given [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource 31 answers I wanted to arrange the array of table list with sort() function but i am getting same kind of warning my code as follows : and the warning i am getting are : Warning: sort() expects parameter 1 to be array, resource given in C:\wamp\www\Copy (4) of st_db_1\test_2.php on line 9 Warning: Invalid argument supplied for foreach() in C:\wamp\www\Copy (4) of st_db_1\test_2.php on line

Native C++ float array to C# float array using Marshal.Copy NOT working for some of the data

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am seeing a pretty bizarre issue while trying to pass an array from C++ to C#. I am using Marshal.Copy (specifically: https://msdn.microsoft.com/en-us/library/a53bd6cz(v=vs.110).aspx ). Problem: float array from C++ to C# is yielding a few NaN 's in the resulting array. (Note: I am working in the context of the Unity game engine) Code Example C++ code: extern "C" bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API getSomeFloats(float** points, int* count) { std::vector results; std::vector key_points = for (auto iter = key_points.begin(); iter

Divide one numpy array by another only where both arrays are non-zero

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What's the easiest, most Pythonic way to divide one numpy array by another (of the same shape, element-wise) only where both arrays are non-zero? Where either the divisor or dividend is zero, the corresponding element in the output array should be zero. (This is the default output when the divisor is zero, but np.nan is the default output when the dividend is zero.) 回答1: This still tries to divide by 0, but it gives the correct result: np.where(b==0, 0, a/b) To avoid doing the divide-by-zero, you can do: m = b!=0 c = np.zeros_like(a) np

Sorting an array using multiple sort criteria (QuickSort)

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to find out how (using a quicksort algorithm) to sort an struct array by 2 criterias. For example say I had a struct of: struct employee { char gender [ 12 ]; char name [ 12 ]; int id ; }; Say my input is: struct employee arr [ 3 ]= { { "male" , "Matt" , 1234 }, { "female" , "Jessica" , 2345 }, { "male" , "Josh" , 1235 } }; I am wanting to sort the elements by gender first then the IDs in ascending order. An example would be have all the males printed first with their IDs in order and then all the females with theirs. I

Why array implements IList?

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: See the definition of System.Array class public abstract class Array : IList, ... Theoretically, I should be able to write this bit and be happy int[] list = new int[] {}; IList iList = (IList)list; I also should be able to call any method from the iList ilist.Add(1); //exception here My question is not why I get an exception, but rather why Array implements IList ? 回答1: Because an array allows fast access by index, and IList / IList is are the only collection interfaces that support this. So perhaps your real question is "Why is there no

Transposing a NumPy array

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I use Python and NumPy and have some problems with "transpose": a=array([5,4]) print a print a.T Invoking a.T is not transposing the array. If a is for example [[],[]] then it transposes correctly, but I need the transpose of [...,...,...] . 回答1: It's working exactly as it's supposed to. The transpose of a 1D array is still a 1D array! (If you're used to matlab, it fundamentally doesn't have a concept of a 1D array. Matlab's "1D" arrays are 2D.) If you want to turn your 1D vector into a 2D array and then transpose it, just slice it with np

“Invalid parameter number: parameter was not defined” Inserting data

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: UPDATE I was making a petty mistake when listing the VALUES. I should have put ":username" and not ":alias". I suppose the answer credit to this question is free reign for anyone who wants it? Or do I delete the question? ORIGINAL I've been using Yii's active record pattern for a while. Now, my project needs to access a different database for one small transaction. I thought the Yii's DAO would be good for this. However, I'm getting a cryptic error. CDbCommand failed to execute the SQL statement: SQLSTATE[HY09 3 ]: Invalid