multidimensional-array

How do I search a multi-dimensional array?

允我心安 提交于 2020-01-02 05:44:13
问题 In C#, Array.Find<T>(arrayName, value); searches a one dimensional array. Is there anyway to do this for a multidimensional array (e.g. myArray[,,] )? 回答1: Working with Excel and VSTO, I deal with multidimensional arrays all the time. There are no built-in functions for multidimensional array like Array.Find(). You basically have two choices: create your own helper methods and implement a generic search pattern there, or generate a list of domain objects correlating to the contents of the

Perform numpy exp function in-place

荒凉一梦 提交于 2020-01-02 05:36:09
问题 As in title, I need to perform numpy.exp on a very large ndarray, let's say ar , and store the result in ar itself. Can this operation be performed in-place? 回答1: You can use the optional out argument of exp : a = np.array([3.4, 5]) res = np.exp(a, a) print(res is a) print(a) Output: True [ 29.96410005 148.4131591 ] exp(x[, out]) Calculate the exponential of all elements in the input array. Returns out : ndarray Output array, element-wise exponential of x . Here all elements of a will be

Json.NET: deserialize nested arrays into strongly typed object

ぐ巨炮叔叔 提交于 2020-01-02 04:31:09
问题 I'm writing client application, which should process server responses. Responses are in JSON. I decided to use Json.NET to deserialize them. And I couldn't simplify or modify those responses (on server side). Particular difficulties of this specific JSON response is that different object types is in same array: hash and array of files. So, I would like to deserialize this array straight ahead into strongly typed object, rather than array of objects. I think that it should be possible to

Please clarify the following Python NumPy array initialization and splicing examples

谁说我不能喝 提交于 2020-01-02 04:24:05
问题 I am using Python version 2.6 and am learning NumPy version 1.3. I have tried out several NumPy array initialization and column splicing examples below, and added some inline questions as comments and a list of findings in the end. Hopefully someone can explain to me what is behind the differences in behaviors. Lots of inter-related questions and a rather long post, but each example is small, feel free to just answer one or a couple. import numpy as np print "Initializing a number of numpy

I need an array_keys_recursive()

牧云@^-^@ 提交于 2020-01-02 04:10:27
问题 $temp = array(); function show_keys($ar) { foreach ($ar as $k => $v ) { $temp[] = $k; if (is_array($ar[$k])) { show_keys ($ar[$k]); } } return $temp; } I tried using that function but it still only returns the first key. 回答1: Using SPL, looping over the keys is quite easy (store them in another array if you wish): <?php $arr = array_fill(0,8,range(0,3)); var_dump($arr); foreach( new RecursiveIteratorIterator( new RecursiveArrayIterator($arr), RecursiveIteratorIterator::SELF_FIRST) as $key =>

joining two numpy matrices

孤街醉人 提交于 2020-01-02 03:44:06
问题 If you have two numpy matrices, how can you join them together into one? They should be joined horizontally, so that [[0] [1] [[0][1] [1] + [0] = [1][0] [4] [1] [4][1] [0]] [1]] [0][1]] For example, with these matrices: >>type(X) >>type(Y) >>X.shape >>Y.shape <class 'numpy.matrixlib.defmatrix.matrix'> <class 'numpy.matrixlib.defmatrix.matrix'> (53, 1) (53, 1) I have tried hstack but get an error: >>Z = hstack([X,Y]) Traceback (most recent call last): File "labels.py", line 85, in <module> Z =

php array generation challenge

陌路散爱 提交于 2020-01-02 01:56:07
问题 I need to randomly generate an two-dimensional n by n array. In this example, n = 10. The array should have this structure. One example: $igra[]=array(0,1,2,3,4,5,6,7,8,9); $igra[]=array(6,9,1,5,0,2,7,3,4,8); $igra[]=array(2,5.................... $igra[]=array(1,7..................... $igra[]=array(5,4................... $igra[]=array(4,2................... $igra[]=array(9,0..................... $igra[]=array(8,3..................... $igra[]=array(7,6.................... $igra[]=array(3,8....

How to map a 2-d matrix in Java to Hibernate/JPA?

跟風遠走 提交于 2020-01-02 01:30:07
问题 I have a legacy database I'm trying to redesign into the 21st century. One of the existing data structures involves a particular class which contains a 2-dimensional matrix of values. If I were to reverse-engineer this class from the database, I'd end up with a series of attributes like: private BigDecimal NODE_1_MATRIX_POS_1_1; private BigDecimal NODE_1_MATRIX_POS_1_2; and so on. Since this is a 6x6 matrix, there are a lot of such columns. I've been looking for a better way, but I'm not sure

C++ Accessing Successive Values in a 2D Array by Pointer

孤人 提交于 2020-01-01 19:17:28
问题 I understand how to access elements in a 2D array by pointer, but I'm having a bit of trouble accessing the second "element" in an array row and using it to make comparisons. For example, if I had the array: int numbers[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; I would need to access the elements 2, 5, and 8 for another function. But when I declare a pointer and point it to the next element in an array, like so: int (*p)[3] = &(numbers[1]); or int (*p)[3] = numbers + 1; It points to the next

Can you throw within a conditional expression? (was: How can bounds-checking be extended to multiple dimensions?)

浪子不回头ぞ 提交于 2020-01-01 18:12:37
问题 Note: I solved the original problem by realizing a completely different one. See the addendum for the new actual problem, but you can read the previous part for context. This is an extension of one of my previous posts. I made a container class based on that answer: template < typename T, unsigned N0, unsigned ...N > struct array_md { // There's a class template specialization with no extents. // Imagine the various N... components are bracket-enclosed instead // of comma-separated. And if "N