numpy

Find all shortest Euclidean distances between two groups of point coordinates

左心房为你撑大大i 提交于 2021-02-11 13:15:05
问题 I have a Pandas DataFrame, where columns X1, Y1 have point coordinates for the first group of coordinates and columns X2, Y2 have point coordinates for the second group of coordinates. Both groups are independent of each other. It is just happen to be they are in the same dataframe. Example: X1,Y1,X2,Y2 41246.438,0.49,38791.673,0.49 41304.5,0.491,38921.557,0.491 41392.062,0.492,39037.135,0.492 41515.5,0.493,39199.972,0.493 41636.062,0.494,39346.561,0.494 41795.188,0.495,39477.63,0.495 42027

Histogram `bins` must increase monotonically matplotlib

自作多情 提交于 2021-02-11 13:12:58
问题 this is my code: import numpy as np import matplotlib.pyplot as plt data = np.genfromtxt("C:\\Users\\pearl\\Downloads\\Age group.csv", delimiter=',', names=True, dtype=('U7','U40','U13',int)) x= ['15-19','20-24', '25-29','30-34','35-39','40-44'] y = data[data['birth_type'] == 'Single Birth']['total_number_of_mother'] plt.hist(x,y) plt.show() However, I am getting a value error saying bins must increase monotonically. May I get some help? 来源: https://stackoverflow.com/questions/65263726

Histogram `bins` must increase monotonically matplotlib

夙愿已清 提交于 2021-02-11 13:12:20
问题 this is my code: import numpy as np import matplotlib.pyplot as plt data = np.genfromtxt("C:\\Users\\pearl\\Downloads\\Age group.csv", delimiter=',', names=True, dtype=('U7','U40','U13',int)) x= ['15-19','20-24', '25-29','30-34','35-39','40-44'] y = data[data['birth_type'] == 'Single Birth']['total_number_of_mother'] plt.hist(x,y) plt.show() However, I am getting a value error saying bins must increase monotonically. May I get some help? 来源: https://stackoverflow.com/questions/65263726

Find all shortest Euclidean distances between two groups of point coordinates

旧巷老猫 提交于 2021-02-11 13:12:20
问题 I have a Pandas DataFrame, where columns X1, Y1 have point coordinates for the first group of coordinates and columns X2, Y2 have point coordinates for the second group of coordinates. Both groups are independent of each other. It is just happen to be they are in the same dataframe. Example: X1,Y1,X2,Y2 41246.438,0.49,38791.673,0.49 41304.5,0.491,38921.557,0.491 41392.062,0.492,39037.135,0.492 41515.5,0.493,39199.972,0.493 41636.062,0.494,39346.561,0.494 41795.188,0.495,39477.63,0.495 42027

numpy genfromtxt not applying missing_values

ぐ巨炮叔叔 提交于 2021-02-11 12:58:24
问题 I am currently struggling with a really simple problem, but cannot seem to solve it. You can reproduce the issue with the following file and code: test.csv 2020081217,28.6 2020081218,24.7 2020081219,-999.0 2020081220,-999.0 2020081221,-999.0 code data = np.genfromtxt("C:/Users/col/Downloads/test.csv", delimiter=',', missing_values=["-999", "-999.0", -999, -999.0]) print(data) output [[ 2.02008122e+09 2.86000000e+01] [ 2.02008122e+09 2.47000000e+01] [ 2.02008122e+09 -9.99000000e+02] [ 2

numpy genfromtxt not applying missing_values

倾然丶 夕夏残阳落幕 提交于 2021-02-11 12:57:53
问题 I am currently struggling with a really simple problem, but cannot seem to solve it. You can reproduce the issue with the following file and code: test.csv 2020081217,28.6 2020081218,24.7 2020081219,-999.0 2020081220,-999.0 2020081221,-999.0 code data = np.genfromtxt("C:/Users/col/Downloads/test.csv", delimiter=',', missing_values=["-999", "-999.0", -999, -999.0]) print(data) output [[ 2.02008122e+09 2.86000000e+01] [ 2.02008122e+09 2.47000000e+01] [ 2.02008122e+09 -9.99000000e+02] [ 2

How to apply a natural logarithm to a matrix and obtain zero for when the matrix entry is zero

走远了吗. 提交于 2021-02-11 12:47:24
问题 In Python I have a Matrix with some zero values, how can I apply a natural logarithm and obtain zero for when the matrix entry is zero? I am using numpy.log(matrix) to apply the natural logarithm function, but I am getting nan when the matrix entry is equal to zero, and I would like it to be zero instead 回答1: You can do something like this: arr = numpy.nan_to_num(numpy.log(matrix)) The behavior of nan_to_num replaces all the NaNs by zeroes. You can find more information here: https://docs

How to create a column in a Pandas dataframe based on a conditional substring search of one or more OTHER columns

半腔热情 提交于 2021-02-11 12:44:18
问题 I have the following data frame: import pandas as pd df = pd.DataFrame({'Manufacturer':['Allen Edmonds', 'Louis Vuitton 23', 'Louis Vuitton 8', 'Gulfstream', 'Bombardier', '23 - Louis Vuitton', 'Louis Vuitton 20'], 'System':['None', 'None', '14 Platinum', 'Gold', 'None', 'Platinum 905', 'None'] }) I would like to create another column in the data frame named Pricing , which contains the value "East Coast" if the following conditions hold: a) if a substring in the Manufacturer column matches

How to center the nonzero values within 2D numpy array?

此生再无相见时 提交于 2021-02-11 12:35:04
问题 I'd like to locate all the nonzero values within a 2D numpy array and move them so that the image is centered. I do not want to pad the array because I need to keep it the same shape. For example: my_array = np.array([[1, 1, 0, 0], [0, 0, 2, 4], [0, 0, 0, 0], [0, 0, 0, 0]]) # center... >>> [[0 0 0 0] [0 1 1 0] [0 2 4 0] [0 0 0 0]] But in reality the arrays I need to center are much larger (like 200x200, 403x403, etc, and they are all square). I think np.nonzero and np.roll might come in handy

How to center the nonzero values within 2D numpy array?

六月ゝ 毕业季﹏ 提交于 2021-02-11 12:34:11
问题 I'd like to locate all the nonzero values within a 2D numpy array and move them so that the image is centered. I do not want to pad the array because I need to keep it the same shape. For example: my_array = np.array([[1, 1, 0, 0], [0, 0, 2, 4], [0, 0, 0, 0], [0, 0, 0, 0]]) # center... >>> [[0 0 0 0] [0 1 1 0] [0 2 4 0] [0 0 0 0]] But in reality the arrays I need to center are much larger (like 200x200, 403x403, etc, and they are all square). I think np.nonzero and np.roll might come in handy