array

IE9 JavaScript array initialization bug

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Apparently JS implementation in IE9 contains (IMO, critical) bug in handling array literals. In IE9 in some cases this code: var a = [1,2,3,4,]; will create array of length 5 with last element equals to undefined . Here are two versions of my KiTE engine test pages: http://terrainformatica.com/kite/test-kite.htm - works in IE9 http://terrainformatica.com/kite/test-kite-ie9-bug.htm - fails in IE9 The only difference is that first document contains data.contacts property initialized as [1,2,3,4] and second one as [1,2,3,4,] . Internal IE

Making my NumPy array shared across processes

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have read quite a few of the questions on SO about sharing arrays and it seems simple enough for simple arrays but I am stuck trying to get it working for the array I have. import numpy as np data=np.zeros(250,dtype='float32, (250000,2)float32') I have tried converting this to a shared array by trying to somehow make mp.Array accept the data , I have also tried creating the array as using ctypes as such: import multiprocessing as mp data=mp.Array('c_float, (250000)c_float',250) The only way I have managed to get my code working is not

C weird array syntax in multi-dimensional arrays

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've known that this is true: x[4] == 4[x] What is the equivalent for multi-dimensional arrays? Is the following true? x[4][3] == 3[x[4]] == 3[4[x]] 回答1: x[y] is defined as *(x + (y)) x[y][z] would become *(*(x + (y)) + z) x[y[z]] would become *(x + (*(y + (z)))) x[4][3] would become *(*(x + (4)) + 3) would become *(*(x + 4) + 3) 3[x[4]] would become *(3 + (*(x + (4)))) would become *(*(x + 4) + 3) 3[4[x]] would become *(3 + (*(4 + (x)))) would become *(*(x + 4) + 3) Which means they are all equivalent. 回答2: Yes. In each case x is an array

Convert var_dump of array back to array variable

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have never really thought about this until today, but after searching the web I didn't really find anything. Maybe I wasn't wording it right in the search. Given an array (of multiple dimensions or not): $data = array('this' => array('is' => 'the'), 'challenge' => array('for' => array('you'))); When var_dumped: array(2) { ["this"]=> array(1) { ["is"]=> string(3) "the" } ["challenge"]=> array(1) { ["for"]=> array(1) { [0]=> string(3) "you" } } } The challenge is this: What is the best optimized method for recompiling the array to a useable

cpython vs cython vs numpy array performance

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am doing some performance test on a variant of the prime numbers generator from http://docs.cython.org/src/tutorial/numpy.html . The below performance measures are with kmax=1000 Pure Python implementation, running in CPython: 0.15s Pure Python implementation, running in Cython: 0.07s def primes(kmax): p = [] k = 0 n = 2 while k Pure Python+Numpy implementation, running in CPython: 1.25s import numpy def primes(kmax): p = numpy.empty(kmax, dtype=int) k = 0 n = 2 while k Cython implementation using int*: 0.003s from libc.stdlib cimport

Comparing two numpy arrays for equality, element-wise

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the simplest way to compare two numpy arrays for equality (where equality is defined as: A = B iff for all indices i: )? Simply using == gives me a boolean array: >>> numpy.array([1,1,1]) == numpy.array([1,1,1]) array([ True, True, True], dtype=bool) Do I have to and the elements of this array to determine if the arrays are equal, or is there a simpler way to compare? 回答1: (A==B).all() test if all values of array (A==B) are True. Edit (from dbaupp's answer and yoavram's comment) It should be noted that: this solution can have a

Malicious code vulnerability - May expose internal representation by returning reference to mutable object

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi I'm getting the violation as below: Malicious code vulnerability - May expose internal representation by returning reference to mutable object in my code i wrote like this public String[] chkBox() { return chkBox; } How we can solve it. 回答1: As the error message states, you're returning internal state (chkBox is - most likely - part of the internal state of an object even though you're not showing its definition) This can cause problems if you - for example - do String[] box = obj.chkBox(); box[0] = null; Since an array object, as all

Python List of np arrays to array

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to turn a list of 2d numpy arrays into a 2d numpy array. For example, dat_list = [] for i in range ( 10 ): dat_list . append ( np . zeros ([ 5 , 10 ])) What I would like to get out of this list is an array that is (50, 10). However, when I try the following, I get a (10,5,10) array. output = np . array ( dat_list ) Thoughts? 回答1: you want to stack them: np . vstack ( dat_list ) 转载请标明出处: Python List of np arrays to array 文章来源: Python List of np arrays to array

How to overwrite array inside h5 file using h5py

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to overwrite a numpy array that's a small part of a pretty complicated h5 file. I'm extracting an array, changing some values, then want to re-insert the array into the h5 file. I have no problem extracting the array that's nested. f1 = h5py . File ( file_name , 'r' ) X1 = f1 [ 'meas/frame1/data' ]. value f1 . close () My attempted code looks something like this with no success: f1 = h5py . File ( file_name , 'r+' ) dset = f1 . create_dataset ( 'meas/frame1/data' , data = X1 ) f1 . close () As a sanity check, I executed

getting the opposite diagonal of a numpy array

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So in numpy arrays there is the built in function for getting the diagonal indices, but I can't seem to figure out how to get the diagonal starting from the top right rather than top left. This is the normal code to get starting from the top left: >>> import numpy as np >>> array = np.arange(25).reshape(5,5) >>> diagonal = np.diag_indices(5) >>> array array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) >>> array[diagonal] array([ 0, 6, 12, 18, 24]) so what do I use if I want it to