下面的代码产生编译器错误Variable HEIGHT might not have been initialized(同样如此WIDTH).
我怎样才能声明一个未初始化的静态最终变量,就像我在下面尝试做的那样?
public static final int HEIGHT, WIDTH;
static{
try {
currentImage = new Image("res/images/asteroid_blue.png");
WIDTH = currentImage.getWidth();
HEIGHT = currentImage.getHeight();
}catch (SlickException e){
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) 今天我为C安装了Allegro游戏编程库,我试图包含其中一个头文件但是当我尝试gcc -I./include example.c -o a.exe在终端中执行时,我不断收到此错误:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
(maybe you meant: __al_mangled_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我使用以下说明安装了Allegro 5:https://wiki.allegro.cc/index.php?title = Install_Allegro5_From_GIT/OSX
example.c代码:
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, const char *argv[]){
puts(“Hello, world!”);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个数字列表,将其与长度相对应可得出高斯。我想在这个高斯上计算标准偏差,但是我得到的值(使用np.std()函数)显然太小了(我得到的数值为0.00143…当它应该为8.234时……)。我想我一直在计算y轴上的标准偏差,而不是x轴上的标准偏差(这是应该在标准偏差上进行计算的),但是我对如何做到这一点有些困惑?
我已经包含了我的代码和我要计算std开发的高斯图片。
#max_k_value_counter counts the number of times the maximum value of k comes up.
max_k_value_counter_sum = sum(max_k_value_counter)
prob_max_k_value = [0] * len(max_k_value_counter)
# Calculate the probability of getting a particular value for k
for i in range(len(max_k_value_counter)):
prob_max_k_value[i] = float(max_k_value_counter[i]) / max_k_value_counter_sum
print "Std dev on prob_max_k_value", np.std(prob_max_k_value)
# Plot p(k) vs k_max to calculate the errors on k
plt.plot(range(len(prob_max_k_value)), prob_max_k_value)
plt.xlim(0, 200)
plt.xlabel(r"$k$", fontsize=16)
plt.ylabel(r"$p(k)$", fontsize=16)
plt.show()
Run Code Online (Sandbox Code Playgroud)

我已经习惯了 Scala 中的各种数据结构,我注意到这个函数(人为的例子)应该将可变数组中的每个字符向右移动一个,对数组没有影响:
def shiftRight(str: String): Array[Char] = {
val chars = str.toCharArray
for(i <- chars.length - 1 until 0) chars(i) = chars(i - 1)
chars
}
println(shiftRight("ABCD").mkString)
Run Code Online (Sandbox Code Playgroud)
产生结果
ABCD
Run Code Online (Sandbox Code Playgroud)
不是预期的
AABC
Run Code Online (Sandbox Code Playgroud)