我想得到以下日期的平均值.我考虑过将所有数据转换为秒,然后对它们求平均值.但是可能有更好的方法.
date = ['2016-02-23 09:36:26', '2016-02-24 10:00:32', '2016-02-24 11:28:22', '2016-02-24 11:27:20', '2016-02-24 11:24:15', '2016-02-24 11:20:25', '2016-02-24 11:17:43', '2016-02-24 11:12:03', '2016-02-24 11:09:11', '2016-02-24 11:08:44', '2016-02-24 11:05:28', '2016-02-24 11:03:23', '2016-02-24 10:58:08', '2016-02-24 10:53:59', '2016-02-24 10:49:34', '2016-02-24 10:43:33', '2016-02-24 10:35:27', '2016-02-24 10:31:50', '2016-02-24 10:31:17', '2016-02-24 10:30:05', '2016-02-24 10:29:21']
Run Code Online (Sandbox Code Playgroud)
讨厌的解决方案:
import datetime
import time
import numpy as np
date = ['2016-02-23 09:36:26', '2016-02-24 10:00:32', '2016-02-24 11:28:22', '2016-02-24 11:27:20', '2016-02-24 11:24:15', '2016-02-24 11:20:25', '2016-02-24 11:17:43', '2016-02-24 11:12:03', '2016-02-24 11:09:11', '2016-02-24 11:08:44', '2016-02-24 11:05:28', '2016-02-24 11:03:23', …Run Code Online (Sandbox Code Playgroud) 目前我正在尝试pi = n*(sin(180/n));在xcode中实现此公式.但只是这样写它给了我很大的数字,如-12425553或23082083.我怎么能解决它?
我用过int n; double pi;.
更新:
我尝试使用M_PI/180转换为度,但它仍然无法正常工作.有什么建议??
pi = n*sin((180/n) * (M_PI/180));
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我删除了星号!!
例如,我有以下号码:
0x FF 00 FF
Run Code Online (Sandbox Code Playgroud)
现在,我希望00部分只有在它为0时才是1.我需要检查每个字节还是有一个可以在这里使用的位技巧?
例:
我有一个无符号长IP,我用字符串函数散列它,但函数终止于空字节,所以我需要将所有空字节设置为1:
0x7F000001(127.0.0.1,可以是0x0100007F但是依赖于平台)
现在,我想将0字节变为1:
0x7F010101(因此它将变为127.1.1.1)
这是实现我想要的唯一方式
char ip_sz[5];
*(unsigned long*)ip_sz = ulong_ip;
if (!ip_sz[0]) ip_sz[0] = 1;
if (!ip_sz[1]) ip_sz[1] = 1;
if (!ip_sz[2]) ip_sz[2] = 1;
if (!ip_sz[3]) ip_sz[3] = 1;
Run Code Online (Sandbox Code Playgroud)
?
真的,好奇心.我不关心性能,因为我知道编译器无论如何都会优化它.
以下代码行输出 SyntaxError: invalid syntax
for (i in range(-WIDTH,WIDTH)):
Run Code Online (Sandbox Code Playgroud)
下一个工作没有错误.我不知道这里应该是什么语法错误.所以我只是出于好奇而问.我猜测括号会阻止表达式的评估.
for i in range(-WIDTH,WIDTH):
Run Code Online (Sandbox Code Playgroud) 我试图从javascript数组中显示六个图像.运行下面的代码我没有得到任何结果它似乎没有工作.我不知道我的错在哪里.
这是javascript代码:
var backgroundImage = new Array();
backgroundImage[0] = "images/colors-wallpaper.jpg";
backgroundImage[1] = "images/florida-birds.jpg";
backgroundImage[2] = "images/focus-on-life.jpg";
backgroundImage[3] = "images/set-into-life.jpg";
backgroundImage[4] = "images/dandelion.jpg";
backgroundImage[5] = "images/flowers.jpg";
backgroundImage[5] = "images/flowers.jpg";
function displayAllImages() {
// Here has to be some error!!! //
for (i=0;i<backgroundImage.length;i++) {
document.write("<li><img src='" + backgroundImage[i] + "' width="160" height="120"/><span>" + backgroundImage[i] + "</span></li>");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的HTML代码:
<html>
<head>
<script type="text/javaScript" src="changebackground.js"></script>
</head>
<body>
<div id="container">
<div class="backgoundImage">
<ul>
<script>displayAllImages();</script>
</ul>
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我在描述中尝试了几次字符串.但它不断输出字符串而不是图像.链接在这里 http://wenti.de/resize.php.
源代码如下,
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, "thesitewizard.com",
$text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
Run Code Online (Sandbox Code Playgroud)
有没有base64转换的解决方法?
我对c ++很新,但我正在尝试建立一个非常简单的c ++项目.您可以在下面找到目前的代码.但我遇到的麻烦是数学函数p = n^2-8n+7;.有什么建议我怎么能改进它?
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
/* Variable Declaration */
int p,n,i;
for (n=0; n<100; n++) {
/* Math Function */
p = n^2-8n+7;
/* Check if prime */
for (i=2; i<p; i++) {
if (!(p%i)) break;
else cout << "(" << n << "," << p << ");" << endl;
}
}
/* Ready */
printf("\n\n\a");
system("pause");
}
Run Code Online (Sandbox Code Playgroud)