我有一个庞大的数据集,我需要将图分成网格并计算每个网格方块内的点数。我正在遵循此处概述的方法:
下面是我的代码的精简版本:
import numpy as np
import matplotlib.pyplot as plt
x = [ 1.83259571, 1.76278254, 1.38753676, 1.6406095, 1.34390352, 1.23045712, 1.85877565, 1.26536371, 0.97738438]
y = [ 0.04363323, 0.05235988, 0.09599311, 0.10471976, 0.1134464, 0.13962634, 0.17453293, 0.20943951, 0.23561945]
gridx = np.linspace(min(x),max(x),11)
gridy = np.linspace(min(y),max(y),11)
grid, _, _ = np.histogram2d(x, y, bins=[gridx, gridy])
plt.figure()
plt.plot(x, y, 'ro')
plt.grid(True)
plt.figure()
plt.pcolormesh(gridx, gridy, grid)
plt.plot(x, y, 'ro')
plt.colorbar()
plt.show()
Run Code Online (Sandbox Code Playgroud)
出现问题的地方是网格将绘图的元素识别为点出现的位置,但其中一些元素中没有点;同样,当出现一些实际数据点时,网格不会将它们识别为实际上不存在。
可能是什么原因导致这个问题?另外,很抱歉没有附上剧情,我是新用户,我的声誉还不够高。
更新 这是生成 100 个随机点并尝试将它们绘制在二维直方图中的代码:
import numpy as np
import matplotlib.pyplot as plt
x = …Run Code Online (Sandbox Code Playgroud) 我正在开发一个用 LibGdx 引擎和 Java 编写的新游戏。我在这个游戏中遇到了一些物理问题。
我想以弹道轨迹(愤怒的小鸟风格)射箭,但找不到这样做的方程式。
我正在使用这些速度方程:
float velx = (float) (Math.cos(rotation) * spd);
float vely = (float) (Math.sin(rotation) * spd);
Run Code Online (Sandbox Code Playgroud)
我将其添加到当前位置,箭头朝一个方向射出 - 直线。
我想也许改变旋转会帮助我实现我想要的(弹道路径)。
它确实有帮助,但我也想拥有轨迹。
我看到有人已经发布了这个 ProjectileEquation 类,但不知道如何使用它:
public class ProjectileEquation
{
public float gravity;
public Vector2 startVelocity = new Vector2();
public Vector2 startPoint = new Vector2();
public Vector2 gravityVec = new Vector2(0,-10f);
public float getX(float n) {
return startVelocity.x * (n ) + startPoint.x;
}
public float getY(float n) {
float t = n;
return 0.5f * gravity …Run Code Online (Sandbox Code Playgroud) 我在 Windows 7 上运行 rStudio v3.1.2。这台笔记本电脑是 64 位机器。
我正在参加 Coursera 提供的 JHU R 编程课程,但我在问题的第 1 部分中遇到了一个错误。我有一些错误处理函数,我没有考虑到这个例子,所以我真的只是想展示我绝对需要的东西。我包含这些消息的唯一原因是证明必须满足所有条件才能继续。
pollutantmean <- function(directory, pollutant, id=1:332) {
setwd("C:\\Users\\WR-eSUB\\specdata")
if(!isValidDirectory(directory)) {
stop("Invalid input given. Please specify valid directory to operate on.")
}
if(!isValidPollutant(pollutant)) {
stop("Invalid input given. Please specify valid pollutant (nitrate/sulfate).")
}
if(!isValidIdRange(id)) {
stop("Invalid input given. Please specify valid id range (1:332).")
}
sortedData = numeric()
for (i in id) {
thisFileName = paste(formatC(i, width = 3, flag = "0"), ".csv", sep="")
thisFileRead = …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用 Pandas、JSON 和 Python 3.4 从文本文件中打印数据。
当我在朋友的机器上使用 Python 2.7 运行代码时,它运行良好,但不适用于 Python 3.4。
这是我的代码:
import json
import pandas as pd
tweets_data_path = 'tweets.txt'
tweets_data = []
tweets_file = open(tweets_data_path, "r")
for line in tweets_file:
try:
tweet = json.loads(line)
tweets_data.append(tweet)
except:
continue
print (len(tweets_data))
tweets = pd.DataFrame()
tweets['text'] = map(lambda tweet: tweet['text'], tweets_data)
tweets['lang'] = map(lambda tweet: tweet['lang'], tweets_data)
tweets['country'] = map(lambda tweet: tweet['place']['country'] if tweet['place'] != None else None, tweets_data)
for i in range(len(tweets_data)):
print(tweets['text'][i])
Run Code Online (Sandbox Code Playgroud)
它不打印推文数据,而是打印数据的内存位置。例如
<map object at 0x04988050>
<map …Run Code Online (Sandbox Code Playgroud) 我编写了下面的代码,用于获取最大值和最小值作为我的MOOC分配的一部分.该程序不断地从用户接收输入,直到用户键入"完成".
输入'done'后,程序会给出最大值和最小值的结果.问题是最大值的结果总是正确的,但最小值的结果总是"无".
largest = None
smallest = None
while ( True ) :
inp = raw_input('Enter a number: ')
if inp == 'done' :
break
try:
inp = float(inp)
except:
print 'Invalid input'
continue
if inp is None or inp > largest:
largest = inp
if inp is None or inp < smallest:
smallest = inp
print largest, smallest
Run Code Online (Sandbox Code Playgroud) 我需要使用 TensorFlow Probability 从伯努利分布中采样来实现马尔可夫链蒙特卡罗。但是,我的尝试显示的结果与我对伯努利分布的期望不一致。
我在这里修改了 tfp.mcmc.sample_chain(从对角线方差高斯采样)示例的文档中给出的示例,以从伯努利分布中提取。由于伯努利分布是离散的,我使用了 RandomWalkMetropolis 转换内核而不是 Hamiltonian Monte Carlo 内核,我预计它不会工作,因为它计算梯度。
这是代码:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions
def make_likelihood(event_prob):
return tfd.Bernoulli(probs=event_prob,dtype=tf.float32)
dims=1
event_prob = 0.3
num_results = 30000
likelihood = make_likelihood(event_prob)
states, kernel_results = tfp.mcmc.sample_chain(
num_results=num_results,
current_state=tf.zeros(dims),
kernel = tfp.mcmc.RandomWalkMetropolis(
target_log_prob_fn=likelihood.log_prob,
new_state_fn=tfp.mcmc.random_walk_normal_fn(scale=1.0),
seed=124
),
num_burnin_steps=5000)
chain_vals = states
# Compute sample stats.
sample_mean = tf.reduce_mean(states, axis=0)
sample_var …Run Code Online (Sandbox Code Playgroud) 为什么赋值形式为int = int*double会给出错误,而int*= double形式的赋值不会产生错误(在Java中)?
例:
public class TestEmp {
public static void main(String[] args) {
double e = 10;
int r = 1;
r *= e;
r = r * e;
System.out.println("De uitkomst van r :" + r);
}
}
Run Code Online (Sandbox Code Playgroud)
r *= e被接受,r = r * e不是.为什么?
我的每个变量都是一个独立的列表.
我在这里使用另一个线程上找到的方法.
import numpy as np
import statsmodels.api as sm
y = [1,2,3,4,3,4,5,4,5,5,4,5,4,5,4,5,6,5,4,5,4,3,4]
x = [
[4,2,3,4,5,4,5,6,7,4,8,9,8,8,6,6,5,5,5,5,5,5,5],
[4,1,2,3,4,5,6,7,5,8,7,8,7,8,7,8,7,7,7,7,7,6,5],
[4,1,2,5,6,7,8,9,7,8,7,8,7,7,7,7,7,7,6,6,4,4,4]
]
def reg_m(y, x):
ones = np.ones(len(x[0]))
X = sm.add_constant(np.column_stack((x[0], ones)))
for ele in x[1:]:
X = sm.add_constant(np.column_stack((ele, X)))
results = sm.OLS(y, X).fit()
return results
Run Code Online (Sandbox Code Playgroud)
我唯一的问题是,在我的回归输出中,解释变量标记为x1,x2,x3等.想知道是否有可能将这些更改为更有意义的名称?
谢谢
我是一个初学者,我遇到了以下问题:
\nimport tactic.linarith\nimport tactic.suggest\n\nnoncomputable theory\nopen_locale classical\n\nlemma two_ne_four_mul_any (n:\xe2\x84\x95) : 2 \xe2\x89\xa0 2 * 2 * n := begin\n cases n,\n linarith,\n rw mul_assoc,\n ???\nend\nRun Code Online (Sandbox Code Playgroud)\n现在的状态是:
\nn : \xe2\x84\x95\n\xe2\x8a\xa2 2 \xe2\x89\xa0 2 * (2 * n.succ)\nRun Code Online (Sandbox Code Playgroud)\n它看起来如此微不足道,以至于我认为必须有一种策略来解决它。但 linarith、ring、simpl、trivial 不起作用。
\n那么,我是否错过了一些重要的内容?
\n我还尝试使用现有的引理来解决这个问题。第一步我想达到:
\nn : \xe2\x84\x95\n\xe2\x8a\xa2 1 \xe2\x89\xa0 2 * n.succ\nRun Code Online (Sandbox Code Playgroud)\n希望某些更高级别的策略现在能够看到这是真的。但是,我不知道如何对方程两边进行一些操作。两边都除以2不是应该有可能吗?
\n我的计划是继续将 rhs 更改为 2*(n+1) 和 2n+2,也许目标是
\n\xe2\x8a\xa2 0 \xe2\x89\xa0 2 * n + 1\nRun Code Online (Sandbox Code Playgroud)\n希望在图书馆找到适用的引理。
\n当我运行下面的代码时,会弹出以下消息框.为什么要打印那些我不想要它们的烦人牙箍呢?我使用的是Python 2.7和EasyGui.

from __future__ import division
from easygui import *
import ystockquote
def main():
PRHSX_message()
def PRHSX_message():
prhsx_share_price = float(ystockquote.get_last_trade_price('PRHSX'))
prhsx_daily_change = ystockquote.get_change('PRHSX')
prhsx_total_shares = 47.527
prhsx_starting_value = 2500
prhsx_percent_change = (((prhsx_share_price * prhsx_total_shares) / prhsx_starting_value) - 1) * 100
prhsx_percent_change = str("%.2f" % prhsx_percent_change) + "%"
prhsx_current_value = prhsx_share_price * prhsx_total_shares
prhsx_profit = prhsx_current_value - prhsx_starting_value
prhsx_current_value = "$" + str("%.2f" % prhsx_current_value)
prhsx_profit = "$" + str("%.2f" % prhsx_profit)
prhsx_string = "T. Rowe Price Roth IRA Account\n____________________________\n \ …Run Code Online (Sandbox Code Playgroud) 我正在尝试这个查询:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label
WHERE
{
?AGE rdfs:label ?label.
}
Run Code Online (Sandbox Code Playgroud)
AGE我需要模型中的所有值,但此查询为我提供了具有相同属性 label 的其他资源值。
例如,我已连接资源gender以拥有属性rdfs:label。所以在我的结果中我得到了年龄值和性别值。
谁能告诉我我哪里错了?
我有一个关于GIT分支的查询,文档似乎没有涵盖它.
场景:
我有一个申请.
我想做一些编辑,所以我在我的存储库上创建了一个分支.
我在分支上提交.
现在,如何在实时环境中查看这些编辑,而无需将它们提交给主实时应用程序.
在提交到主应用程序之前,我显然需要在实时环境中检查编辑?
我错过了什么吗?
python ×4
python-2.7 ×2
2d ×1
double ×1
easygui ×1
formatting ×1
git ×1
github ×1
int ×1
java ×1
json ×1
lean ×1
libgdx ×1
matplotlib ×1
multiplying ×1
numpy ×1
pandas ×1
physics ×1
r ×1
read.csv ×1
regression ×1
rstudio ×1
sparql ×1
statsmodels ×1
string ×1
tensorflow ×1
twitter ×1