小编dam*_*gad的帖子

使用API​​在Google电子表格中添加多行

我需要在google电子表格中添加多行(几百行).目前我正在循环中这样做:

for row in rows
   _api_client.InsertRow(row, _spreadsheet_key, _worksheet_id)
Run Code Online (Sandbox Code Playgroud)

这是非常慢的,因为行是逐个添加的.

有什么方法可以加快速度吗?

python gdata google-spreadsheet-api

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

matplotlib 中无效的 rgba arg“#”

我无法弄清楚在尝试在 matplotlib 中创建散点图时如何使用颜色。

我正在尝试绘制具有不同颜色点的多个散点图来显示集群。

colors=['#12efff','#eee111','#eee00f','#e00fff','#123456','#abc222','#000000','#123fff','#1eff1f','#2edf4f','#2eaf9f','#22222f'
        '#eeeff1','#eee112','#00ef00','#aa0000','#0000aa','#000999','#32efff','#23ef68','#2e3f56','#7eef1f','#eeef11']
C=1
fig = plt.figure()
ax = fig.gca(projection='3d')
for fgroups in groups:
   X=[np.random.rand(50),np.random.rand(50),np.random.rand(50)]
   y=[np.random.rand(50),np.random.rand(50),np.random.rand(50)]
   Z=[np.random.rand(50),np.random.rand(50),np.random.rand(50)]
   C=(C+1) % len(colors)
   ax.scatter(X,Y,Z, s=20, c=colors[C], depthshade=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)

我收到的错误如下:

ValueError: to_rgba: 无效的 rgba arg "#" to_rgb: 无效的 rgb arg "#" 无法将字符串转换为浮点数: #

看起来它将这些 RGB 参数视为浮点数。

然而,在 matplotlib 文档中,颜色是以这种风格编写的http://matplotlib.org/api/colors_api.html

我缺少什么?

python matplotlib scatter-plot

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

Variadic CRTP模板类,其中一个字段使用constexpr,基于参数类列表

我写了(在c ++ 11中)一个可变参数模板constexpr函数,它计算参数类型的最大大小,例如:

maxSizeof<int, char, MyType>()
Run Code Online (Sandbox Code Playgroud)

这工作正常.然后我想有一个可变参数模板类,其中一个字段是一个大小等于maxSizeof()的数组.这也应该正常工作:

template <typename... TypesT>
    class Myclass {
        uint8_t field[maxSizeOf<TypesT...>()]
    }
Run Code Online (Sandbox Code Playgroud)

但我还需要Myclass为每个参数类型声明方法.我通过以下方式使用CRTP:

template <typename... TypesT>
class Myclass;

template <>
class Myclass {
    uint8_t field[maxSizeOf<TypesT...>()] // (1) Couldn't do it here as there are no `TypesT`
}

template <typename FirstT, typename... OtherT>
class Myclass<FirstT, OtherT...> : public Myclass<OtherT...> {
    public:
        virtual void doSomething(FirstT object) = 0;
    private:
        uint8_t field[maxSizeOf<FirstT, OtherT...>()] // (2) Shouldn't do it here as it will create field for …
Run Code Online (Sandbox Code Playgroud)

c++ variadic-templates c++11

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