我的程序应该拍摄一张图像并将其垂直分割成n个部分,然后将这些部分保存为单独的png文件.对于2个部分,它看起来应该是这样的
我现在遇到了问题,我得到的是我的图像的前半部分被正确保存,然后当它试图裁剪下半部分时我收到以下错误:
SystemError: tile cannot extend outside image
我正在使用的图像有
它计算裁剪的矩形是:
(0.0, 0, 590.0, 842) - 这很正常(590.0, 0, 590.0, 842) - 这会导致程序崩溃我的问题是:为什么这个子矩形超出范围,如何修复它以正确地将我的图像切成两半,如图所示?
from PIL import Image, ImageFilter
im = Image.open("image.png")
width, height = im.size
numberOfSplits = 2
splitDist = width / numberOfSplits #how many pixels each crop should be in width
print(width, height) #prints 1180, 842
for i in range(0, numberOfSplits):
x = splitDist * i
y = 0
w = splitDist
h = height
print(x, y, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的桌面PC上运行一个可在互联网上公开的烧瓶服务器.我做了以下事情:
我使用以下代码作为测试Web服务器
from flask import Flask, request, redirect
app = Flask(__name__)
@app.route("/")
def hello_world():
return "Test 123 "
if __name__ == "__main__":
app.run(host="0.0.0.0", port="33")
Run Code Online (Sandbox Code Playgroud)
当我打开浏览器:http://192.168.1.11:33 /页面显示正常时,我看到"测试123"
当我尝试从我的公共IP地址连接到我的网络服务器时出现问题当我打开我的浏览器到 http://xx.xxx.xxx.xx:30(我的IP地址)时,我看到的是"这个网站不能是到了,xx.xxx.xxx.xx拒绝连接"
我查了所有堆栈溢出的答案,我做了以下事情:
代码运行的屏幕截图显示错误:http://i.imgur.com/a05GvEs.png
我的问题是:我需要做什么才能从我的公共IP地址看到我的烧瓶服务器?
我有一个看起来像这样的字符串
16427171479924442928230863465674813919123162824586<br>17866458359124566529476545682848912883142607690042<br>2421902671055626321111109370544217506941658960408<br>07198403850962455444362981230987879927244284909188<br>
Run Code Online (Sandbox Code Playgroud)
它实际上是一个没有换行符的网格(只有<br>,没有实际换行符(\n))
16427171479924442928230863465674813919123162824586<br>
17866458359124566529476545682848912883142607690042<br>
24219022671055626321111109370544217506941658960408<br>
07198403850962455444362981230987879927244284909188<br>
Run Code Online (Sandbox Code Playgroud)
我想加粗这个网格的某个部分,每次都可以改变,这个例子让我说要粗体8617.(这个数字可以更长,拉伸多行,我的实际网格要大得多)
我希望它看起来像这样:
164271714799244429282308634656748139191231628245 86
17 866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
我试过用这个(maxStr是我要替换的数字串)
gridString.replace(maxStr, "<strong>" + maxStr + "</strong>")
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为字符串包含<br>在其中,所以我实际需要替换的字符串是86<br>17
我的问题是:如何在保持<br>我需要它的地方的同时,用粗体版本替换延伸到多行的数字的某一部分.
JSFiddle说明了我的问题: https ://jsfiddle.net/5d21c2r3/
附注:我想一个解决方案,我删除了所有<br>从我的网格,然后替换的文本,然后重新添加<br>每50个字符,但没有工作,要么是因为<strong>和</strong>最终加入了很多字.
在pygame中,我pygame.draw.rect(screen, color, rectangle)在程序中使用了所有矩形。我希望能够将这些矩形旋转到任意角度。我已经看到以下代码来旋转图像,但是我的问题是RECTANGLES。
pygame.transform.rotate(image, angle)
Run Code Online (Sandbox Code Playgroud)
但是我正在使用矩形,但是我没有可以旋转的图像或“表面”。当我尝试旋转一个矩形
rect = pygame.draw.rect(screen, self.color, self.get_rectang())
rotatedRect = pygame.transform.rotate(rect, self.rotation)
screen.blit(rotatedRect)
Run Code Online (Sandbox Code Playgroud)
这给出TypeError: must be pygame.Surface, not pygame.Rect了.rotate()
我的问题是,如何(x,y,w,h)在pygame中旋转a并显示RECTANGLE 而不是图像。
这是“潜在重复项”的链接文章不是重复项。一个答案解释了旋转矩形的后果,另一个答案使用代码旋转图像。
我有一个使用此源的azure功能设置:
module.exports = function(context, req) {
//this is the entire source, seriously
context.done(null, {favoriteNumber : 3});
};
Run Code Online (Sandbox Code Playgroud)
当我使用像postman这样的工具来访问它时,我得到一个不错的JSON输出,就像我想要的那样:
{
"favoriteNumber": 3
}
Run Code Online (Sandbox Code Playgroud)
问题是当我在浏览器(chrome,firefox等)中访问它时,我看到:
<ArrayOfKeyValueOfstringanyType xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><KeyValueOfstringanyType><Key>favoriteNumber</Key><Value xmlns:d3p1="http://www.w3.org/2001/XMLSchema" i:type="d3p1:int">3</Value></KeyValueOfstringanyType></ArrayOfKeyValueOfstringanyType>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用子进程从另一个 python 脚本中运行 python 脚本。(无需导入,我希望它适用于任何程序,而不仅仅是 python)
这是第一个文件:getting_input.py
name = input("Sample input prompt: ")
Run Code Online (Sandbox Code Playgroud)
这是我用来运行任何 shell 命令的文件:test.py
import subprocess
proc = subprocess.Popen("python getting_input.py", stdout=subprocess.PIPE)
for char in iter(lambda: proc.stdout.read(1).decode('utf-8'), ''):
print(char) # This actually works, printing every character on a new line
Run Code Online (Sandbox Code Playgroud)
但是,当我唯一改变的是添加end=""到我的打印语句中时,绝对不会打印任何内容。
import subprocess
proc = subprocess.Popen("python getting_input.py", stdout=subprocess.PIPE)
for char in iter(lambda: proc.stdout.read(1).decode('utf-8'), ''):
print(char, end="") # This doesn't work, nothing at all gets printed... ????
Run Code Online (Sandbox Code Playgroud)
我假设这是某种缓冲问题,但即使我在其python -u test.py内部使用它运行它python -u getting_input.py,我仍然看不到任何输出。有任何想法吗?
下面的代码将无法编译,因为编译器认为我不应该分配,t1因为它是借用的,但实际上函数always_returns_no_lifetime将始终返回实际上没有生命周期的枚举的变体,所以它可以我修改t1.如何让编译器理解这一点,或者我应该如何重新组织我的代码以避免发生此错误?
#[derive(Clone)]
enum Types<'a> {
NoLifetime(i32),
AlsoNoLifetime(i32),
AlsoAlsoNoLifetime(i32),
HasLifetime(&'a str)
}
fn always_returns_no_lifetime<'a>(some_type: &'a Types) -> Types<'a> {
match *some_type {
Types::HasLifetime(text) => panic!("I only return the type that has no lifetime"),
_ => some_type.clone()
}
}
fn main() {
let mut t1 = Types::NoLifetime(20);
let copy = always_returns_no_lifetime(&t1);
t1 = Types::NoLifetime(30);
}
Run Code Online (Sandbox Code Playgroud)
错误是:
error[E0506]: cannot assign to `t1` because it is borrowed
--> src/main.rs:23:5
|
21 | let copy = always_returns_no_lifetime(&t1);
| …Run Code Online (Sandbox Code Playgroud) 我似乎使用 np.fft.fft 计算原始波的不正确振幅。
显示了 fft 的图,您可以看到显示的幅度约为 3 和 1.5,但如果您查看代码,我将使用幅度 7 和 3 来生成信号。该图应该有两个尖峰,在 x=13 处达到 y=3,在 x=15 处达到 y=7
我需要做什么才能在图表中看到正确的幅度(3 和 7)?
我可以通过实验看到我需要将振幅乘以 2.3 左右的常数,但如何准确计算这个数字呢?
import numpy as np
import matplotlib.pyplot as plt
t0 = 0
t1 = 20
n_samples = 1000
xs = np.linspace(t0, t1, n_samples)
# Generate signal with amplitudes 7 and 3
ys = 7*np.sin(15 * 2 * np.pi * xs) + 3*np.sin(13 * 2 * np.pi * xs)
np_fft = np.fft.fft(ys)
amplitudes = 1/n_samples * np.abs(np_fft) …Run Code Online (Sandbox Code Playgroud) 我试图破解Udacity深度学习课程(作业3 - 正规化)和Tensorflow mnist_with_summaries.py教程中的代码.我的代码似乎运行正常
https://github.com/llevar/udacity_deep_learning/blob/master/multi-layer-net.py
但是有些奇怪的事情正在发生.分配都使用0.5的学习率,并且在某些时候引入指数衰减.但是,当我将学习率设置为0.001(衰减或不衰减)时,我放在一起的代码只运行良好.如果我将初始速率设置为0.1或更高,我会收到以下错误:
Traceback (most recent call last):
File "/Users/siakhnin/Documents/workspace/udacity_deep_learning/multi-layer-net.py", line 175, in <module>
summary, my_accuracy, _ = my_session.run([merged, accuracy, train_step], feed_dict=feed_dict)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 340, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 564, in _run
feed_dict_string, options, run_metadata)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 637, in _do_run
target_list, options, run_metadata)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 659, in _do_call
e.code)
tensorflow.python.framework.errors.InvalidArgumentError: Nan in summary histogram for: layer1/weights/summaries/HistogramSummary
[[Node: layer1/weights/summaries/HistogramSummary = HistogramSummary[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](layer1/weights/summaries/HistogramSummary/tag, layer1/weights/Variable/read)]]
Caused by op u'layer1/weights/summaries/HistogramSummary', defined at:
File "/Users/siakhnin/Documents/workspace/udacity_deep_learning/multi-layer-net.py", line 106, …Run Code Online (Sandbox Code Playgroud) 我从json字符串开始,看起来像: ["2016-05-28", "2016-05-29", "2016-05-30", "2016-05-31"]
我正在尝试将其转换为Saturday 5/28 Sunday 5/29.
我查看了这些答案并试图实现相同的目的: 为什么Date.parse会给出不正确的结果?并将 字符串中的日期转换为日期对象以插入数据库.
但我得到了错误的一天输出.5/28出现Tuesday, 5/28在星期六.
JSFiddle:https://jsfiddle.net/pum40hyx/
这是我的代码,我将日期转换为我想要的字符串:
function convertToNiceDate(inputDate)
{
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var splitString = inputDate.split("-");
currentDate = new Date(splitString[0], splitString[1], splitString[2]);
var day = currentDate.getDate();
var month = currentDate.getMonth();
//this is the problematic line!
var dayOfWeek = days[currentDate.getDay()];
var dateString = dayOfWeek + ", " + month + "/" + day;
return …Run Code Online (Sandbox Code Playgroud) python ×6
javascript ×3
json ×2
azure ×1
crop ×1
date ×1
enums ×1
flask ×1
image ×1
jquery ×1
node.js ×1
numpy ×1
printing ×1
pygame ×1
python-3.x ×1
rectangles ×1
regex ×1
rotation ×1
rust ×1
subprocess ×1
tensorflow ×1
webserver ×1