numpy

Python: Get array indexes of quartiles

随声附和 提交于 2021-02-08 09:13:57
问题 I am using the following code to calculate the quartiles of a given data set: #!/usr/bin/python import numpy as np series = [1,2,2,2,2,2,2,2,2,2,2,5,5,6,7,8] p1 = 25 p2 = 50 p3 = 75 q1 = np.percentile(series, p1) q2 = np.percentile(series, p2) q3 = np.percentile(series, p3) print('percentile(' + str(p1) + '): ' + str(q1)) print('percentile(' + str(p2) + '): ' + str(q2)) print('percentile(' + str(p3) + '): ' + str(q3)) The percentile function returns the quartiles, however, I would also like

Python: Get array indexes of quartiles

馋奶兔 提交于 2021-02-08 09:13:01
问题 I am using the following code to calculate the quartiles of a given data set: #!/usr/bin/python import numpy as np series = [1,2,2,2,2,2,2,2,2,2,2,5,5,6,7,8] p1 = 25 p2 = 50 p3 = 75 q1 = np.percentile(series, p1) q2 = np.percentile(series, p2) q3 = np.percentile(series, p3) print('percentile(' + str(p1) + '): ' + str(q1)) print('percentile(' + str(p2) + '): ' + str(q2)) print('percentile(' + str(p3) + '): ' + str(q3)) The percentile function returns the quartiles, however, I would also like

Smoothing a 2-D Numpy Array with a Kernel

霸气de小男生 提交于 2021-02-08 08:42:37
问题 Suppose I have an (m x n) 2-d numpy array that are just 0's and 1's. I want to "smooth" the array by running, for example, a 3x3 kernel over the array and taking the majority value within that kernel. For values at the edges, I would just ignore the "missing" values. For example, let's say the array looked like import numpy as np x = np.array([[1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 1, 1, 0], [0, 1, 1, 1, 1, 0, 1,

Smoothing a 2-D Numpy Array with a Kernel

久未见 提交于 2021-02-08 08:42:09
问题 Suppose I have an (m x n) 2-d numpy array that are just 0's and 1's. I want to "smooth" the array by running, for example, a 3x3 kernel over the array and taking the majority value within that kernel. For values at the edges, I would just ignore the "missing" values. For example, let's say the array looked like import numpy as np x = np.array([[1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 1, 1, 0], [0, 1, 1, 1, 1, 0, 1,

Smoothing a 2-D Numpy Array with a Kernel

核能气质少年 提交于 2021-02-08 08:42:05
问题 Suppose I have an (m x n) 2-d numpy array that are just 0's and 1's. I want to "smooth" the array by running, for example, a 3x3 kernel over the array and taking the majority value within that kernel. For values at the edges, I would just ignore the "missing" values. For example, let's say the array looked like import numpy as np x = np.array([[1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 1, 1, 0], [0, 1, 1, 1, 1, 0, 1,

Getting eigenvalues from 3x3 matrix in Python using Power method

不想你离开。 提交于 2021-02-08 08:41:48
问题 I'm trying to get all eigenvalues from a 3x3 matrix by using Power Method in Python. However my method returns diffrent eigenvalues from the correct ones for some reason. My matrix: A = [[1, 2, 3], [2, 4, 5], [3, 5,-1]] Correct eigenvalues: [ 8.54851285, -4.57408723, 0.02557437 ] Eigenvalues returned by my method: [ 8.5485128481521926, 4.5740872291939381, 9.148174458392436 ] So the first one is correct, second one has wrong sign and the third one is all wrong. I don't know what I'm doing

cosd and sind with sympy

泪湿孤枕 提交于 2021-02-08 08:38:38
问题 There seems to be no equivalent for cosd , sind in sympy (ie cosine and sine for arguments in degrees). Is there any simple way to implement those functions ? For numpy, I did : numpy.cosd = lambda x : numpy.cos( numpy.deg2rad(x) ) Something like : sympy.cosd = lambda x : sympy.cos( sympy.pi/180*x ) works for evaluation, but the expression is printed as : cos(pi*x/180) which is not great for readability (I have complicated expression due to 3D coordinates changes). Is there any way to create

Loading large data into TensorFlow 2.0 without loading it on the RAM

匆匆过客 提交于 2021-02-08 08:30:31
问题 I have processed and saved a large dataset of video and audio file (about 8 to 9 GB of data) The data is saved as 2 numpy arrays, one for each modality Shapes of the files are (number_of_examples, maximum_time_length, feature_length) I want to use this data for training my Neural Network for a classification task I am using the TensorFlow 2.0 Beta version I am running all the codes on Google Colab (after installing tf-2.0 beta) Each time I loading the data in tf.data the entire RAM of the

Numpy array neither C or F contiguous implications

限于喜欢 提交于 2021-02-08 08:30:31
问题 TL;DR Question Regarding numpy arrays that are neighter C or F contiguous (array's c_contiguous and f_contiguous flags are False): Can an array really be neither C or F contiguous? Or falsy flags just mean numpy can't figure out the correct contigious type? What are the performance implications on such arrays? Are there any optimizations we miss when staying in this state? An array for example: import numpy as np arr = np.random.randint(0, 255, (1000, 1000, 3), dtype='uint8') arr = arr[:, :,

Numpy array neither C or F contiguous implications

戏子无情 提交于 2021-02-08 08:30:09
问题 TL;DR Question Regarding numpy arrays that are neighter C or F contiguous (array's c_contiguous and f_contiguous flags are False): Can an array really be neither C or F contiguous? Or falsy flags just mean numpy can't figure out the correct contigious type? What are the performance implications on such arrays? Are there any optimizations we miss when staying in this state? An array for example: import numpy as np arr = np.random.randint(0, 255, (1000, 1000, 3), dtype='uint8') arr = arr[:, :,