numpy

Numpy Histogram Representing Floats with Approximate Values as The Same

北城余情 提交于 2021-02-09 20:50:17
问题 I have code that generates a certain value from -10 to 10 given a range from [0,1) The code takes the value from -10 to 10 and it will append it to a list, according to its probability. For example, -10 would be put in the list 0 times since it corresponds to the value 0, and 10 would be put 100 times (as a normalization) since it corresponds to 1 in the range. Here is the code: #!/usr/bin/env python import math import numpy as np import matplotlib.pyplot as plt pos = [] ceilingValue = 0.82

Numpy Histogram Representing Floats with Approximate Values as The Same

佐手、 提交于 2021-02-09 20:41:41
问题 I have code that generates a certain value from -10 to 10 given a range from [0,1) The code takes the value from -10 to 10 and it will append it to a list, according to its probability. For example, -10 would be put in the list 0 times since it corresponds to the value 0, and 10 would be put 100 times (as a normalization) since it corresponds to 1 in the range. Here is the code: #!/usr/bin/env python import math import numpy as np import matplotlib.pyplot as plt pos = [] ceilingValue = 0.82

Least squares in a set of equations with optimize.leastsq() (Python)

陌路散爱 提交于 2021-02-09 15:49:04
问题 I have two functions and a set of data. Both functions have the same x data and the same parameters. I want to obtain the parameters by least squares method that makes the best fit of my data. The parameters are: ex,ey,ez. The X data are: RA,DE (like 3000 points). The Y data are: dRA,dDE. I tried this but I obtained a wrong solution: def residuals(p, dRA, dDE, RA, DEC): ex,ey,ez = p f1 = dRA-(ex*sin(DEC)*cos(RA)+ey*sin(DEC)*sin(RA)-ez*cos(DEC)) f2 = dDE-(-ex*sin(RA)+ey*cos(RA)) err = np

Least squares in a set of equations with optimize.leastsq() (Python)

人盡茶涼 提交于 2021-02-09 15:46:38
问题 I have two functions and a set of data. Both functions have the same x data and the same parameters. I want to obtain the parameters by least squares method that makes the best fit of my data. The parameters are: ex,ey,ez. The X data are: RA,DE (like 3000 points). The Y data are: dRA,dDE. I tried this but I obtained a wrong solution: def residuals(p, dRA, dDE, RA, DEC): ex,ey,ez = p f1 = dRA-(ex*sin(DEC)*cos(RA)+ey*sin(DEC)*sin(RA)-ez*cos(DEC)) f2 = dDE-(-ex*sin(RA)+ey*cos(RA)) err = np

你用 Python 写过最牛逼的程序是什么?

那年仲夏 提交于 2021-02-09 11:31:32
编译:Python开发者 - Jake_on 英文:Quora http://python.jobbole.com/85986/ 有网友在 Quora 上提问,「你用 Python 写过最牛逼的程序/脚本是什么?」。本文摘编了 3 个国外程序员的多个小项目,含代码。 Manoj Memana Jayakumar, 3000+ 顶 更新:凭借这些脚本,我找到了工作!可看我在这个帖子中的回复,《Has anyone got a job through Quora? Or somehow made lots of money through Quora?》 1. 电影/电视剧 字幕一键下载器 我们经常会遇到这样的情景,就是打开字幕网站subscene 或者opensubtitles, 搜索电影或电视剧的名字,然后选择正确的抓取器,下载字幕文件,解压,剪切并粘贴到电影所在的文件夹,并且需把字幕文件重命名以匹配电影文件的名字。是不是觉得太无趣呢?对了,我之前写了一个脚本,用来下载正确的电影或电视剧字幕文件,并且存储到与电影文件所在位置。所有的操作步骤仅需一键就可以完成。懵逼了吗? 请看这个 Youtube 视频:https://youtu.be/Q5YWEqgw9X8 源代码 存放在GitHub: subtitle-downloader 更新: 目前,该脚本支持多个字幕文件同时下载。步骤

sklearn dimensionality issues “Found array with dim 3. Estimator expected <= 2”

倖福魔咒の 提交于 2021-02-09 11:13:22
问题 I am trying to use KNN to correctly classify .wav files into two groups, group 0 and group 1. I extracted the data, created the model, fit the model, however when I try and use the .predict() method I get the following error: Traceback (most recent call last): File "/..../....../KNN.py", line 20, in <module> classifier.fit(X_train, y_train) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/neighbors/base.py", line 761, in fit X, y = check_X_y(X, y,

Why can't I subtract one date period from the next and convert to an integer?

风格不统一 提交于 2021-02-09 11:12:24
问题 I am trying to determine whether a difference between two months is an even or odd number of months. I used the command: import pandas as pd (pd.to_datetime('2019-01-01').to_period('M') - pd.to_datetime('2018-08-01').to_period('M')) % 2 This seems to work in python 3.6.7, but in another python 3.7.3 environment I get the error: >>> import pandas as pd >>> (pd.to_datetime('2019-01-01').to_period('M') - pd.to_datetime('2018-08-01').to_period('M')) % 2 Traceback (most recent call last): File "

How can I rotate a 3d array (nxnxn) by x degrees around x, y, and z axes?

让人想犯罪 __ 提交于 2021-02-09 11:12:23
问题 I have a 3d array created with numpy, and I was wondering how I can rotate it by a custom angle, not just the rot90 function that numpy has. Can anyone help? The 3d matrix represents an image (such as a cube, or some other shape) ie 0: 1 1 1 1 1 1 1 1 1: 1 1 1 1 2: 1 1 1 1 1 1 1 1 EDIT: Moved solution to answer 回答1: Have a look at the scipy.ndimage.interpolation.rotate function. The reason this is in scipy and not in numpy is that rotating an image 90 degrees is done by just chaning the

sklearn dimensionality issues “Found array with dim 3. Estimator expected <= 2”

依然范特西╮ 提交于 2021-02-09 11:12:20
问题 I am trying to use KNN to correctly classify .wav files into two groups, group 0 and group 1. I extracted the data, created the model, fit the model, however when I try and use the .predict() method I get the following error: Traceback (most recent call last): File "/..../....../KNN.py", line 20, in <module> classifier.fit(X_train, y_train) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/neighbors/base.py", line 761, in fit X, y = check_X_y(X, y,

Why can't I subtract one date period from the next and convert to an integer?

与世无争的帅哥 提交于 2021-02-09 11:10:44
问题 I am trying to determine whether a difference between two months is an even or odd number of months. I used the command: import pandas as pd (pd.to_datetime('2019-01-01').to_period('M') - pd.to_datetime('2018-08-01').to_period('M')) % 2 This seems to work in python 3.6.7, but in another python 3.7.3 environment I get the error: >>> import pandas as pd >>> (pd.to_datetime('2019-01-01').to_period('M') - pd.to_datetime('2018-08-01').to_period('M')) % 2 Traceback (most recent call last): File "