我想使用 div 和 css-grid 编写 2048 游戏。这就是我想象的输出:

我有适合浏览器窗口的外部部分,我只想在中左 div (称为 )的中间(水平和垂直)写入 4x4 网game-container格
<div class = "game-container">
<div class = "game">
<div class = "game-cell"></div>
<!-- 16 game cells total -->
<div class = "game-cell"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我使用以下方法制作了 4x4 网格:
div.game {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(4, 1fr);
}
Run Code Online (Sandbox Code Playgroud)
但是,我有一些问题:
game-cell正方形(假设为 50px)game-cell我可以每一项都做,但不能一次全部做。
另外,如何game在div的中间显示div(如图)game-container。
附言。如果它可以简化某些事情,我不介意使用一些 Bootstrap。
有关外容器的一些信息:
html, body, div.container{
height: 100%;
margin: 0;
padding: 0;
} …Run Code Online (Sandbox Code Playgroud) 我想使用Matplotlib在Jupyter中显示动画.这是一些基本的例子:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)
def update(data):
line.set_ydata(data)
return line,
def data_gen():
while True:
yield np.random.rand(10)
ani = animation.FuncAnimation(fig, update, data_gen, interval=100);
from IPython.display import HTML
HTML(ani.to_jshtml())
Run Code Online (Sandbox Code Playgroud)
当我第一次运行代码时(或重新启动内核后),我得到了我想要的东西: 
但是,当我第二次运行相同的代码时,我会在左下角找到剩余的代码: 
我注意到当我%matplotlib inline在顶部添加时,即使在重新启动内核后我也得到了错误的输出.因此,我的猜测是%matplotlib每次创建动画时都必须将magic命令设置为默认值,但我甚至无法找到是否%matplotlib有默认值.
我用的是Anaconda.以下是我的版本:Conda版本:4.4.10
Python版本:Python 3.6.4 :: Anaconda, Inc.
IPython版本:6.2.1
Jupyter版本:5.4.0
我有一个 1D numpy 数组 X ,其形状为(1000,)。我想在随机(均匀)位置注入 10 个随机(正常)值,从而获得 shape 的 numpy 数组(1010,)。如何在 numpy 中有效地做到这一点?
让说我有一个函数F有两个可选参数par1和par2.
我想写一个新函数:
def some_plot(parameter):
array = []
for n in range(100):
array.append(F(parameter = n))
# make some plot using array
Run Code Online (Sandbox Code Playgroud)
然后我想通过调用some_plot('par1')(或some_plot(par1))分割错误来制作一些情节.
是否可以将参数的名称作为参数传递?
我生成单色图像并使用保存它们imageio.imwrite。每次保存文件时,都会收到以下警告:
WARNING:root:Lossy conversion from float64 to uint8. Range [-0.24890179009891278, 2.35786261304524]. Convert image to uint8 prior to saving to suppress this warning.
Run Code Online (Sandbox Code Playgroud)
我不在乎这种“有损转换”。一切看起来都很好,并且工作正常。
但是,每生成约100张图像,我都会得到不同的警告,我想抓住它们。因此,我想忽略以上内容。
我试图忽略它,但是即使我打电话
import warnings
warnings.simplefilter('ignore')
Run Code Online (Sandbox Code Playgroud)
事先我仍然收到此警告。