我认为'解包'可能是错误的词汇 - 道歉,因为我确信这是一个重复的问题.
我的问题很简单:在一个需要项目列表的函数中,如何在不出错的情况下传递Python列表项?
my_list = ['red', 'blue', 'orange']
function_that_needs_strings('red', 'blue', 'orange') # works!
function_that_needs_strings(my_list) # breaks!
Run Code Online (Sandbox Code Playgroud)
当然必须有一种方法来扩展列表,并'red','blue','orange'在蹄上传递函数?
我们如何绘制2D数学向量matplotlib?有没有人有这方面的例子或建议?
我有几个矢量存储为2D numpy数组,我想将它们绘制为有向边.
要绘制的向量构造如下:
import numpy as np
# a list contains 3 vectors;
# each list is constructed as the tail and the head of the vector
a = np.array([[0, 0, 3, 2], [0, 0, 1, 1], [0, 0, 9, 9]])
Run Code Online (Sandbox Code Playgroud)
编辑:
我刚刚添加了tcaswell对输出感兴趣的人的最终答案的图,并想用matplotlib绘制2d向量:
