在Python中:
fig1, ax1 = plt.subplots()
ax1.set_title('Basic Plot')
ax1.boxplot(data)
Run Code Online (Sandbox Code Playgroud)
IQR 可以通过以下公式计算:
IQR = stats.iqr(data, interpolation = 'midpoint')
Run Code Online (Sandbox Code Playgroud)
我如何获得每个盒印迹的最小值和最大值“晶须”?
digits :: Int -> [Int]
digits n = reverse (x)
where x
| n < 10 = [n]
| otherwise = (mod n 10) : (digits (div n 10))
Run Code Online (Sandbox Code Playgroud)
*ghci> digits 1234 = [3,1,2,4]*
Run Code Online (Sandbox Code Playgroud)
digits' :: Int -> [Int]
digits' n = (x)
where x
| n < 10 = [n]
| otherwise = (mod n 10) : (digits' (div n 10))
Run Code Online (Sandbox Code Playgroud)
*ghci>digits' 1234 = [4,3,2,1]*
Run Code Online (Sandbox Code Playgroud)
按照我的理解,评价digits 1234应该是[1,2,3,4]。但似乎我错过了一些东西。谁能解释一下吗?
我是 Python 新手,我有一个关于 OOP 的问题。因此,当我们创建一个类时,我们在括号中写入“对象”。例如,
\nclass My(object):\nRun Code Online (Sandbox Code Playgroud)\n我在某处读到这意味着该类继承自objectPython 中的类。但我也读到,我们创建的每个类都是该类的一个实例type。所以我的问题是object类与类相同type,如果是,为什么当要求Python打印类的类型时,它返回<class \'type\'>而不是返回<class \'object\'>。另外,为什么我们可以\xe2\x80\x99t写
class My(type):\nRun Code Online (Sandbox Code Playgroud)\n如果object班级和type班级是同一个?
假设我有这个元组列表:
[(30, 'B'), (50, 'B'), (40, 'C'), (10, 'A'), (80, 'A'), (5, 'A')]
Run Code Online (Sandbox Code Playgroud)
我需要按元组的第二个元素按降序对元组进行排序,但条件是具有相同第二个元素的所有元组都彼此相邻。
所以,它应该看起来像
[(80, 'A'), (10, 'A'), (5, 'A'), (50, 'B'), (30, 'B'), (40, 'C')]
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个 python 脚本,它启动一个程序并自动执行它,不断处理新数据并保存到预设目录。
永远运行 Python 脚本、在发生错误时记录错误并在崩溃时重新启动的推荐方法是什么?
到目前为止,我遇到了os.execv并开始:
import sys
import os
def pyexcept(t, v, tb):
import traceback
## restarts the script
os.execv( sys.executable, '')
Run Code Online (Sandbox Code Playgroud)
但是我经常在试图弄清楚下一步时遇到困难,有人可以解释我可以采取的下一步吗,ty!
我正在使用以下代码:
#include <msp430.h>
int flip(int flip){
if (flip) {flip = 0;}
else {flip = 1;}
return flip;
}
/*...*/
void main(void){
int ctrl = 0;
while(1){
ctrl = flip(ctrl);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时出现错误,指的是以下行:
ctrl = flip(ctrl);
error #110: expression preceding parentheses of apparent call must have (pointer-to-) function type
Run Code Online (Sandbox Code Playgroud)
我不明白为什么编译器给我这个错误。
答复是正确的:当我对变量和函数使用相同的名称时,编译器不喜欢它。固定的。
我正在尝试使用线程在后台运行 python http 服务器。我遇到了几个执行以下操作的参考文献:
import threading
import http.server
import socket
from http.server import HTTPServer, SimpleHTTPRequestHandler
debug = True
server = http.server.ThreadingHTTPServer((socket.gethostname(), 6666), SimpleHTTPRequestHandler)
if debug:
print("Starting Server in background")
thread = threading.Thread(target = server.serve_forever)
thread.daemon = True
thread.start()
else:
print("Starting Server")
print('Starting server at http://{}:{}'.format(socket.gethostname(), 6666))
server.serve_forever()
Run Code Online (Sandbox Code Playgroud)
当 thread.daemon 设置为True时,程序将完成而不启动服务器(端口 6666 上没有任何运行)。当我将 thread.daemon 设置为False时,它会在前台启动服务器并阻止终端,直到我手动终止它。
关于如何进行这项工作有什么想法吗?
有了这个定义
struct A {
int x;
};
Run Code Online (Sandbox Code Playgroud)
为什么是
struct A a = {0};
Run Code Online (Sandbox Code Playgroud)
有效语法同时
struct A a;
a = {0};
Run Code Online (Sandbox Code Playgroud)
产生错误,“‘{’标记之前的预期表达式”?
如果我将该行替换为
a = (struct A){0};
Run Code Online (Sandbox Code Playgroud)
那么一切都很好,所以分配给结构不是问题。
我有一本书,上面写着以下内容:
\n\n\nmalloc() 分配仍然存在一个小问题。我们仍然需要解释一下温度 malloc() 的左侧部分。(int\n*) 是做什么用的?
\n(int *) 是一个类型转换。您\xe2\x80\x99在本书中已经看到了其他类型的类型转换。要将 float > 值转换为 int,请将 (int) 放在浮点值之前,如下所示:
\n\n
aVal = (int)salary;类型转换中的 * 表示该类型转换是指针类型转换。\n malloc() 始终返回字符指针。如果您想使用\nmalloc() 分配整数、浮点或除字符之外的任何类型的数据\n,则必须对 malloc() 进行类型转换,以便接收分配的指针\n变量(例如 temps)接收\n正确的指针数据类型。temps 是一个整数指针;您不应该将临时值分配给 malloc()\xe2\x80\x99s 分配的内存,除非您将 nmalloc() 类型转换为整数指针。因此,前一个 malloc() 的左侧只是告诉 malloc() 一个整数指针,而不是默认的字符指针,将指向第一个分配的值。
\n
温度:
\nint * temps; /* Will point to the first heap value */\ntemps = (int *) malloc(10 * sizeof(int)); /* Yikes! */\nRun Code Online (Sandbox Code Playgroud)\n在阅读类似的线程后,据说malloc()返回一个 void 类型的指针,而不是字符类型的指针。我错过了什么吗?我知道不需要类型转换malloc()在 C 中进行类型转换。
我一直在尝试在不使用 string.h 或其他东西的情况下交换数组字符串。我写了一些代码,但它只改变了单词的第一个字母。我哪里做错了?
我的代码是:
#include <stdio.h>
#define SIZE 25
void strswap(char [], char []);
int main(void)
{
char str1 [SIZE], str2 [SIZE];
printf("enter the first string for strswap: ");
scanf("%s", str1);
printf("enter the second string for strswap: ");
scanf("%s", str2);
strswap(str1, str2);
printf("after strswap, the first string is %s, the second string is %s\n", str1, str2);
return 0;
}
void strswap(char str1 [], char str2 [])
{
char temp;
temp=*str1;
*str1=*str2;
*str2=temp;
}
Run Code Online (Sandbox Code Playgroud)
一个例子:
第一个字符串是:苹果
第二个字符串是:你好
最终结果是:hpple & aello
python ×5
c ×4
arrays ×1
class ×1
ghci ×1
haskell ×1
http.server ×1
list ×1
matplotlib ×1
pointers ×1
python-3.x ×1
reverse ×1
struct ×1
swap ×1
tuples ×1
where-clause ×1