numpy-ndarray

Efficiently Calculating a Euclidean Dist Matrix in Numpy?

时光总嘲笑我的痴心妄想 提交于 2020-05-30 08:12:42
问题 I have a large array (~20k entries) of two dimension data, and I want to calculate the pairwise Euclidean distance between all entries. I need the output to have standard square form. Multiple solutions for this problem have been proposed, but none of them seem to work efficiently for large arrays. The method using complex transposing fails for large arrays. Scipy pdist seems to be the most efficient method using numpy. However, using squareform on the result to obtain a square matrix makes

How to multiply two 2D RFFT arrays (FFTPACK) to be compatible with NumPy's FFT?

被刻印的时光 ゝ 提交于 2020-05-20 05:05:50
问题 This bounty has ended . Answers to this question are eligible for a +250 reputation bounty. Bounty grace period ends in 23 hours . karlphillip is looking for a canonical answer : Detailed explanation and source code for a function that performs the correct multiplication of two 2D arrays transformed with FFTPACK RFFT. The validation procedure is already embedded in the code of the question: one simply needs to replace the line that says # this doesn't work with the function call that performs

Why can I not reproduce a nd array manually?

拈花ヽ惹草 提交于 2020-05-17 06:21:09
问题 I'm confused about these data structures. From a GIS system, I use a function to extract the meta data (8 different fields) myList = FeatureClassToNumPyArray(...) myList = [('a', 'b', 'c'...) ('aa', 'bb', 'cc'...) ..] # 8 fields print (type(myList )) print (myList.shape) print (myList.size) This produces: <class 'numpy.ndarray'> (1, 9893) 9893 # I was expecting to get (9893 rows x 8 cols), as in (8,9893) # or (9893, 8), but anyway, let's not worry about that right now. So I try this: >>>

How come not-copying a numpy array changes the data attribute?

余生长醉 提交于 2020-04-13 07:05:51
问题 As my MWE below shows, calling np.array(a, copy=False) on an existing array a returns something that behaves exactly as expected, except that the .data attributes seem to differ. How can this be? >>> a # My original array array([2]) >>> b = np.array(a, copy=False) # Not-a-copy of the original array >>> b is a # The Python objects seem to be identical True >>> b.data is a.data # But their .data attributes aren't?? False >>> a.data <memory at 0x7f82ebd757c8> >>> b.data <memory at 0x7f82ebd75888

How come not-copying a numpy array changes the data attribute?

倾然丶 夕夏残阳落幕 提交于 2020-04-13 07:05:21
问题 As my MWE below shows, calling np.array(a, copy=False) on an existing array a returns something that behaves exactly as expected, except that the .data attributes seem to differ. How can this be? >>> a # My original array array([2]) >>> b = np.array(a, copy=False) # Not-a-copy of the original array >>> b is a # The Python objects seem to be identical True >>> b.data is a.data # But their .data attributes aren't?? False >>> a.data <memory at 0x7f82ebd757c8> >>> b.data <memory at 0x7f82ebd75888

Unexpected behaviour numpy array indexing [duplicate]

杀马特。学长 韩版系。学妹 提交于 2020-04-03 09:59:57
问题 This question already has an answer here : Why using an array as an index changes the shape of a multidimensional ndarray? (1 answer) Closed 10 months ago . The shape of a numpy array is changing when performing specific slicing in a somewhat unexpected manner I have tried several ways of slicing the same array but slight differences lead to different outcomes in the shape of the array import numpy as np z = np.zeros((1,9,10,2)) # This makes sense print(z[...,[1,0]].shape) # (1, 9, 10, 2)

Unexpected behaviour numpy array indexing [duplicate]

烈酒焚心 提交于 2020-04-03 09:56:29
问题 This question already has an answer here : Why using an array as an index changes the shape of a multidimensional ndarray? (1 answer) Closed 10 months ago . The shape of a numpy array is changing when performing specific slicing in a somewhat unexpected manner I have tried several ways of slicing the same array but slight differences lead to different outcomes in the shape of the array import numpy as np z = np.zeros((1,9,10,2)) # This makes sense print(z[...,[1,0]].shape) # (1, 9, 10, 2)

Unexpected behaviour numpy array indexing [duplicate]

半城伤御伤魂 提交于 2020-04-03 09:54:41
问题 This question already has an answer here : Why using an array as an index changes the shape of a multidimensional ndarray? (1 answer) Closed 10 months ago . The shape of a numpy array is changing when performing specific slicing in a somewhat unexpected manner I have tried several ways of slicing the same array but slight differences lead to different outcomes in the shape of the array import numpy as np z = np.zeros((1,9,10,2)) # This makes sense print(z[...,[1,0]].shape) # (1, 9, 10, 2)

Unexpected behaviour numpy array indexing [duplicate]

回眸只為那壹抹淺笑 提交于 2020-04-03 09:49:06
问题 This question already has an answer here : Why using an array as an index changes the shape of a multidimensional ndarray? (1 answer) Closed 10 months ago . The shape of a numpy array is changing when performing specific slicing in a somewhat unexpected manner I have tried several ways of slicing the same array but slight differences lead to different outcomes in the shape of the array import numpy as np z = np.zeros((1,9,10,2)) # This makes sense print(z[...,[1,0]].shape) # (1, 9, 10, 2)

Unexpected behaviour numpy array indexing [duplicate]

前提是你 提交于 2020-04-03 09:48:06
问题 This question already has an answer here : Why using an array as an index changes the shape of a multidimensional ndarray? (1 answer) Closed 10 months ago . The shape of a numpy array is changing when performing specific slicing in a somewhat unexpected manner I have tried several ways of slicing the same array but slight differences lead to different outcomes in the shape of the array import numpy as np z = np.zeros((1,9,10,2)) # This makes sense print(z[...,[1,0]].shape) # (1, 9, 10, 2)