小编inz*_*zzz的帖子

x,= ... - 这个尾随逗号是逗号运算符吗?

我不明白变量后的逗号是什么,意思是:http://matplotlib.org/examples/animation/simple_anim.html

line, = ax.plot(x, np.sin(x))
Run Code Online (Sandbox Code Playgroud)

如果我删除逗号和变量"line",变为变量"line",则程序被破坏.上面给出的url的完整代码:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig = plt.figure()
ax = fig.add_subplot(111)

x = np.arange(0, 2*np.pi, 0.01)        # x-array
line, = ax.plot(x, np.sin(x))

def animate(i):
    line.set_ydata(np.sin(x+i/10.0))  # update the data
    return line,

#Init only required for blitting to give a clean slate.
def init():
    line.set_ydata(np.ma.array(x, mask=True))
    return line,

ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
    interval=25, blit=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)

根据http://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences逗号后变量似乎与仅包含一个项目的元组有关.

python tuples matplotlib

35
推荐指数
2
解决办法
2万
查看次数

由Cygwin打印不可打印的字符

Grepping不可打印的字符似乎不适用于回车(控制键^ M).

usr@R923047 ~
$ head -3 test.ctl
row 1
row 2
row 3
usr@R923047 ~
$ head -3 test.ctl | cat -nv
     1  row 1^M
     2  row 2^M
     3  row 3
usr@R923047 ~
$ head -3 test.ctl | grep '[^[:print:]]'

usr@R923047 ~
$ head -3 test.ctl | grep '[[:cntrl:]]'

usr@R923047 ~
Run Code Online (Sandbox Code Playgroud)

bash shell grep cygwin non-printable

4
推荐指数
1
解决办法
2021
查看次数

使用ArrayList构造函数创建List的转换副本

我不知道你们怎么称呼它,但有可能写出类似的东西吗?只有这两行.

List<Celsius> listOfCelsiuses = new ArrayList<>();
List<Fahrenheit> listOfFahrenheits = new ArrayList<>(listOfCelsiuses);
Run Code Online (Sandbox Code Playgroud)

它基本上需要一个celsiuses列表并返回一个华氏列表.但是我应该在哪里实现转换逻辑?

java collections

1
推荐指数
1
解决办法
61
查看次数

javafx动画:显示圆圈

我想显示5个随机定位的彩色圆圈。这很容易。现在,我想将此代码调整为动画。此应用程序应无休止地生成随机圆圈,但条件是它应仅在屏幕上保留最后五个圆圈。这就是我卡住的地方。JavaFx提供ListChangeListener。我认为这是我应该使用的。但是如何?以下是我未完成的代码:

import java.util.Random;

import javafx.application.Application;
import javafx.collections.ListChangeListener;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class RandomColorTest extends Application {

    int radius = 20;
    int sceneWidth = 300;
    int sceneHeight = 300;

    private void init(Stage primaryStage) {
        Group root = new Group();
        primaryStage.setResizable(false);
        primaryStage.setScene(new Scene(root, sceneWidth,sceneHeight));

        for (int i = root.getChildren().size(); i < 5; i++) {
            root.getChildren().add(createCircle());
            // the following should convey the idea:
            // if the collection holds 5 elements then keep least recently generated element …
Run Code Online (Sandbox Code Playgroud)

java javafx

0
推荐指数
1
解决办法
5930
查看次数

标签 统计

java ×2

bash ×1

collections ×1

cygwin ×1

grep ×1

javafx ×1

matplotlib ×1

non-printable ×1

python ×1

shell ×1

tuples ×1