array

ValueError: cannot reshape array of size 30470400 into shape (50,1104,104)

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to run threw this Tutorial http://emmanuelle.github.io/segmentation-of-3-d-tomography-images-with-python-and-scikit-image.html where I want to do a Segmentation of 3-D tomography images with Python. I'm struggling directly in the beginning, with reshaping the image. This is the code: %matplotlib inline import numpy as np import matplotlib.pyplot as plt import time as time data = np.fromfile('/data/data_l67/dalladas/Python3/Daten/Al8Cu_1000_g13_t4_200_250.vol', dtype=np.float32) data.shape (60940800,) data.reshape((50,1104,104)) -

Is there a good radixsort-implementation for floats in C#

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a datastructure with a field of the float-type. A collection of these structures needs to be sorted by the value of the float. Is there a radix-sort implementation for this. If there isn't, is there a fast way to access the exponent, the sign and the mantissa. Because if you sort the floats first on mantissa, exponent, and on exponent the last time. You sort floats in O(n). 回答1: Update: I was quite interested in this topic, so I sat down and implemented it (using this very fast and memory conservative implementation ). I also read

shallow iteration with nditer

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got such an array: >>>y = np.random.randint(0, 255, (2,2,3)) >>>array([[[242, 14, 211], [198, 7, 0]], [[235, 60, 81], [164, 64, 236]]]) And I have to iterate over each triplet element (unfortunately vectorization won't help me here...). So I tried: for i, j in np.nditer(y): print y[i, j], hoping I'd get such an output: [242, 14, 211], [198, 7, 0], [235, 60, 81], [164, 64, 236] , but no luck! I get the error: Traceback (most recent call last): File " ", line 1, in for i, j in np.nditer(y): print y[i,j] TypeError: iteration over a 0-d

java array traversal in circular manner

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an array which have 1 2 3 4 5 values. array a = [ 1 , 2, 3, 4, 5] Now i want to traverse it in circular manner. like i want to print 2 3 4 5 1 or 3 4 5 1 2 or 5 1 2 3 4 and so on. any algorithm on this? Edit: I want to print all the combination in circular manner. i don't want to state starting point at its initial phase. 回答1: int start = ... for (int i = 0; i < a.length; i++) { System.out.println(a[(i + start) % a.length]); } I should note that this is probably not the most efficient way of expressing the loop ... in terms of

Convert a std::vector to a NumPy array without copying data

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a C++ library which currently has some methods inside which return a std::vector defined like public : const std :: vector <uint32_t> & getValues () const ; I'm currently working on wrapping the whole library for Python using SWIG and this is working well so far. SWIG wraps this getValues() function fine such that it returns a Python tuple. The issue is in my Python-side code I want to convert this to a NumPy array. Of course I can do this by: my_array = np . array ( my_object . getValues (), dtype = 'uint32' ) but this

How to find all ordered pairs of elements in array of integers whose sum lies in a given range of value

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given an array of integers find the number of all ordered pairs of elements in the array whose sum lies in a given range [a,b] Here is an O(n^2) solution for the same ''' counts all pairs in array such that the sum of pair lies in the range a and b ''' def countpairs(array, a, b): num_of_pairs = 0 for i in range(len(array)): for j in range(i+1,len(array)): total = array[i] + array[j] if total >= a and total <= b: num_of_pairs += 1 return num_of_pairs I know my solution is not optimal What is a better algorithm for doing this. 回答1: Sort the

Java: how do i initialize an array size if it&#039;s unknown?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm asking the user to enter some numbers between 1 and 100 and assign them into an array. The array size is not initialized since it is dependent on the number of times the user enters a number. How should i assign the array length?? If user enters 5 6 7 8 9 (5 numbers), then int[] list; becomes int[] list = new int[5]; I'm trying to use a loop, but it won't stop. int[] integers; int j = 0; do { integers = new int[j + 1]; integers[j] = in.nextInt(); j++; } while((integers[j-1] >= 1) ||(integers[j-1]) <= 100); 回答1: You should use a List for

Check arrays for recursion

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the best way to check if an array is recursive in PHP ? Given the following code: <?php $myarray = array('test',123); $myarray[] = &$myarray; print_r($myarray); ?> From the PHP Manual: The print_r() will display RECURSION when it gets to the third element of the array. There doesn't appear to be any other way to scan an array for recursive references, so if you need to check for them, you'll have to use print_r() with its second parameter to capture the output and look for the word RECURSION . Is there more elegant way of checking ?

Could someone help describe the two types of array storage in Javascript?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm reading this article about V8 on HTML5Rocks . The article is old but I understand almost none of it and it bothers me. I'm taking this 1 step at a time but could someone help me with the Arrays section? The article states: Arrays In order to handle large and sparse arrays, there are two types of array storage internally: Fast Elements: linear storage for compact key sets Dictionary Elements: hash table storage otherwise It's best not to cause the array storage to flip from one type to another. Question: What would a Fast Elements linear

numpy array 1.9.2 getting ValueError: could not broadcast input array from shape (4,2) into shape (4)

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Following piece of code was working in numpy 1.7.1 but it is giving value error in the current version. I want to know the root cause of it. import numpy as np x = [1,2,3,4] y = [[1, 2],[2, 3], [1, 2],[2, 3]] a = np.array([x, np.array(y)]) Following is the output I get in numpy 1.7.1 >>>a array([[1, 2, 3, 4], [array([1, 2]), array([2, 3]), array([1, 2]), array([2, 3])]], dtype=object) But the same code produces error in version 1.9.2. ----> 5 a = np.array([x, np.array(y)]) ValueError: could not broadcast input array from shape (4,2) into