array

C function declaration

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: can we declare a function in a header file in following way? extern int ap ( char [][] ); can we use char[][] in function? 回答1: For a two dimensional array, you have to supply a size for the last dimension otherwise the compiler doesn't know how to use it. (it's fine to omit the name though.) like this: extern int ap ( char [][ 10 ] ); 回答2: No, you need to specify the last N-1 dimensions for an array. extern int ap ( char [][ DIMENSION ] ); For more information look here 回答3: char[][] is not a valid array type because you cannot

Hive check elements in array

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an Hive table made of user_id and item_id (id of items that have been purchased by the user). I want to get a list of all the users who purchased item 1 but not item 2 and 3. To do this I wrote the simple query: SELECT user_id, collect_set(item_id) itemslist FROM mytable WHERE item_id in (1, 2) GROUP BY user_id HAVING -- what should I put here??? As you can see, I don't know how to check whether the array itemslist contains 1 and not 2. How do you do this? If there is some more efficient way can you please tell me both (or more)

C-like language without NULL?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi I was recently watching an old video about how null pointers were a billion dollar mistake. He points out both C# and java as they have run-time checks but don't completely eliminate it enough and this is somewhat understandable. He also points out the C at one point which he feels so sure of is a great problem. I get that null terminated strings, arrays with no length and a few other things are bad (billions of dollars on buffer overflow exploits) but to completely remove null? Some languages have made null a thing of the past and other

Getting a grid of a matrix via logical indexing in Numpy

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to rewrite a function using numpy which is originally in MATLAB. There's a logical indexing part which is as follows in MATLAB: X = reshape(1:16, 4, 4).'; idx = [true, false, false, true]; X(idx, idx) ans = 1 4 13 16 When I try to make it in numpy, I can't get the correct indexing: X = np.arange(1, 17).reshape(4, 4) idx = [True, False, False, True] X[idx, idx] # Output: array([6, 1, 1, 6]) What's the proper way of getting a grid from the matrix via logical indexing? 回答1: You could also write: >>> X[np.ix_(idx,idx)] array([[ 1, 4],

check if there exists a[i] = 2*a[j] in an unsorted array a?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given a unsorted sequence of a[1,...,n] of integers, give an O(nlogn) runtime algorithm to check there are two indices i and j such that a[i] =2*a[j]. The algorithm should return i=0 and j=2 on input 4,12,8,10 and false on input 4,3,1,11. I think we have to sort the array anyways which is O(nlogn). I'm not sure what to do after that. 回答1: You're right that the first step is sorting the array. Once the array is sorted, you can find out whether a given element is inside the array in O(log n) time. So if for every of the n elements, you check

Array shifting to the next element

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I move elements in an array to the next element eg: x[5] = { 5, 4, 3, 2, 1 }; // initial values x[0] = 6; // new values to be shifted x[5] = { 6, 5, 4, 3, 2 }; // shifted array, it need to be shifted, // not just increment the values. This what I've done so far. It's wrong, that's why I need help here. Thanks in advance. #include <iostream> using namespace std; int main() { int x[5] = { 5, 4, 3, 2, 1 }; int array_size = sizeof(x) / sizeof(x[0]); x[0] = 6; int m = 1; for(int j = 0; j < array_size; j++) { x[m+j] = x[j]; cout << x[j] <<

deprecation error in sklearn about empty array without any empty array in my code

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am just playing around encoding and decoding but I get this error from sklearn: Warning (from warnings module): File "C:\Python36\lib\site-packages\sklearn\preprocessing\label.py", line 151 if diff: 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. Here is the full code, you can run it yourself in python 3+ My question is why is it saying I use an empty array as I clearly don't in my code, thanks for taking

Copy from IntPtr (16 bit) array to managed ushort

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a IntPtr called rawbits, which points to a 10MB array of data, 16 bit values. I need to return a managed ushort array from that. The following code works but there is an extra BlockCopy I would like to get rid of. Marshal.Copy does not support ushort. What can I do? (FYI: the rawbits is filled in by a video framegrabber card into unmanaged memory) public const int width = 2056; public const int height = 2048; public const int depth = 2; public System.IntPtr rawbits; public ushort[] bits() { ushort[] output = new ushort[width * height]

Methods that change a value, and not return anything

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Please what's the term for methods that alter the contents of a variable, while not returning anything. For instance in Java from the java.util.Arrays class the static method sort sorts an array internally and sets the sorted array to the original arrays variable (not sure). import static java.util.Arrays.sort; public class bs { public static void main(String [] args){ int[] arr = {3,2,4,8,2,5,33,12,19,15,20}; sort(arr); // doing this stuff <<<< and not int [] arr1 = sort(arr); } } 1 - Is there a specific term for that kind of method, and; 2

Set Zend\\Form Error Messages from Controller

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: this is probably a very simple task, but currently I'm failing horribly at it. I just want to add a custom error to my form when my authentication fails. What i tried $form->setMessages(array( array('password' => $this->failedLoginMessage) )); Unexpected Result \Zend\Debug\Debug::dump($form->getMessages()); array(0) {} If i understand the code correctly this should attach an error message to the password element. Actually looking at the setMessages i thought attaching a single-dimension array should have been enough, but it needs the 2nd