小编gre*_*ast的帖子

使用 anaconda 和 VS Code 运行 numpy

我正在尝试让 VScode 与 anaconda 一起使用,但在使用 numpy 时遇到问题。我已经设法让 VScode 使用正确的 python 环境 从 VScode (ctrl+shift+P,输入 Python:Select Interpreter 并选择适当的选项)。

但是,当我在脚本中输入“import numpy”时,我收到以下错误消息:

C:\ProgramData\Anaconda3\envs\sandpit\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\sandpit\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
    from . import multiarray
  File "C:\ProgramData\Anaconda3\envs\sandpit\lib\site-packages\numpy\core\multiarray.py", line 14, …
Run Code Online (Sandbox Code Playgroud)

python numpy anaconda visual-studio-code

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

按集合过滤IEnumerable(Linq)

我想通过它收集的任何对象的特定属性来过滤IEnumerable对象。我希望该选项可以按一个或多个属性值进行过滤,但是要在运行时才知道要过滤多少个值(和哪些值)。

好的,举个例子,收集的对象可以是以下结构:

public struct Person
{
    public string Name { get; set; }
    public string Profession{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)

然后,下面的列表可以使用此结构,我在其中填充了一些任意值:

List<Person> people= new List<Person>;
people.Add(new Person(){Name = "Mickey", Profession="Tinker"};
people.Add(new Person(){Name = "Donald", Profession="Tailor"};
people.Add(new Person(){Name = "Goofy", Profession="Soldier"};
people.Add(new Person(){Name = "Pluto", Profession="Spy"};
Run Code Online (Sandbox Code Playgroud)

然后将其放入IEnumerable(首先将所有这些都转移到它)

var wantedPeople = from n in this.people select n;
Run Code Online (Sandbox Code Playgroud)

假设某个用户只对“ Tailor”和“ Spy”职业感兴趣,并且通过某种gui欺骗的方法创建了以下集合:

List<string> wantedProfessions = new List<string>();
wantedProfessions.Add("Tailor");
wantedProfessions.Add("Spy");
Run Code Online (Sandbox Code Playgroud)

现在,我可以使用哪种Linq语句来归档我的wantPeople,使其仅包含裁缝和间谍条目?我知道我可以使用where子句,但是我不知道如何定制它以得到我想要的东西(而执行以下操作不是我想要的,因为它仅适用于上面的wantProfessions集合(例如,此集合将在运行时更改) ):

wantedPeople = from n in wantedPeople
              where n.Profession == …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

在内存中创建GDI +位图,然后另存为png

我是新的C++和被具有使用GDI +库在存储器中创建新的位图(因此不是打开/读出一个现有的位图)写的函数麻烦; 然后绘制位图; 在保存到png之前.特别是,我在创建位图和保存代码方面遇到了问题.我被限制使用代码块,即使我想,我也不能使用视觉工作室.代码如下:

#include "drawImage.h"
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
#include <stdio.h>
#include <iostream>
using namespace std;
using namespace Gdiplus;

drawImage::drawImage(){}

void drawImage::DrawBitmap(int width, int height){
  GdiplusStartupInput gdiplusStartupInput;
  ULONG_PTR           gdiplusToken;
  GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

  {
    //Create a bitmap
    Bitmap myBitmap(width, height, PixelFormatCanonical);
    Graphics g(&myBitmap);
    Pen blackpen(Color(255,0,0,0), 3);

    //draw on bitmap
    int x1 = 1;
    int x2 = 200;
    int y1 = 1;
    int y2 = 200;
    g.DrawLine(&blackpen, x1,y1,x2,y2);

    // Save bitmap (as a png)
    CLSID pngClsid;
    GetEncoderClsid(L"image/png", &pngClsid);
    myBitmap.Save(L"C:\\test\\test.png", …
Run Code Online (Sandbox Code Playgroud)

c++ gdi+ codeblocks

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

C#列表的乘法

我正在大脑冻结,只是无法找到解决这个问题的方法.

我创建了一个名为CustomSet的类,其中包含一个字符串列表.包含对CustomSet的引用的类将其存储为列表.

public class CustomSet : IEnumerable<string>
{
    public string Name { get; set; }
    internal IList<string> elements;

    public CustomSet(string name)
    {
        this.Name = name;
        this.elements = new List<string>();
    }

    public IEnumerable<string> Elements
    {
        get
        {
            return elements;
        }
    }
    public IEnumerator<string> GetEnumerator()
    {
        return elements.GetEnumerator();
    }
    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我想要做的是迭代这个自定义集列表以输出一个2d字符串数组,其中列是customSet的数量,行是customSet元素的乘法.

例如,如果列表中有3个自定义集:1st有3个元素,2nd有2个元素,3rd有3个元素.我想输出3列和18行(3*2*3).以下代码是尝试解决方案:

CustomSet motion = new CustomSet("Motion");
motion.Elements.Add("low");
motion.Elements.Add("medium");
motion.Elements.Add("high");

CustomSet speed = new CustomSet("Speed");
speed.Elements.Add("slow");
speed.Elements.Add("Fast");

CustomSet mass = new CustomSet("Mass");
mass.Elements.Add("light");
mass.Elements.Add("medium");
mass.Elements.Add("heavy");

List<CustomSet> …
Run Code Online (Sandbox Code Playgroud)

c# multiplication

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