GVKun编程网logo

Numpy nanargmin和nanargmax不适用于datetime-arrays(numpy.ndarray is not callable)

2

最近很多小伙伴都在问Numpynanargmin和nanargmax不适用于datetime-arrays和numpy.ndarrayisnotcallable这两个问题,那么本篇文章就来给大家详细解

最近很多小伙伴都在问Numpy nanargmin和nanargmax不适用于datetime-arraysnumpy.ndarray is not callable这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案、Arrays.sort() VS Arrays.parallelSort()、Code Hunt SECTOR 10 - 11(Jagged Arrays & Arrays 2)、cvxpy 和 numpy 之间的版本冲突:“针对 API 版本 0xe 编译的模块,但此版本的 numpy 是 0xd”等相关知识,下面开始了哦!

本文目录一览:

Numpy nanargmin和nanargmax不适用于datetime-arrays(numpy.ndarray is not callable)

Numpy nanargmin和nanargmax不适用于datetime-arrays(numpy.ndarray is not callable)

如何解决Numpy nanargmin和nanargmax不适用于datetime-arrays?

函数np.nanminnp.nanminnp.nanargminnp.nanargmax应该忽略Nan值,但在datetime64[s]数组中表现出意想不到的行为:>

import numpy as np

a = np.array([''NaT'',''2020-01-30''],dtype=''datetime64[s]'')

#this works as expected
print(''nanmin:'',np.nanmin(a)) # =2020-01-30T00:00:00
print(''nanmax:'',np.nanmax(a)) # =2020-01-30T00:00:00

#this does not
print(''nanargmin:'',np.nanargmin(a)) #should be 1,is 0
print(''nanargmax:'',np.nanargmax(a)) #should be 1,is 0

这是一个错误还是我在这里错过了一些东西?我正在使用numpy 1.19.1。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案

Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案

如何解决Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案?

希望有人能在这里提供帮助。我一直在绕圈子一段时间。我只是想设置一个 python 脚本,它将一些 json 数据从 REST API 加载到云数据库中。我在 Anaconda 上设置了一个虚拟环境(因为 GCP 库推荐这样做),安装了依赖项,现在我只是尝试导入库并向端点发送请求。 我使用 Conda(和 conda-forge)来设置环境并安装依赖项,所以希望一切都干净。我正在使用带有 Python 扩展的 VS 编辑器作为编辑器。 每当我尝试运行脚本时,我都会收到以下消息。我已经尝试了其他人在 Google/StackOverflow 上找到的所有解决方案,但没有一个有效。我通常使用 IDLE 或 Jupyter 进行脚本编写,没有任何问题,但我对 Anaconda、VS 或环境变量(似乎是相关的)没有太多经验。 在此先感谢您的帮助!

  \Traceback (most recent call last):
File "C:\Conda\envs\gcp\lib\site-packages\numpy\core\__init__.py",line 22,in <module>
from . import multiarray
File "C:\Conda\envs\gcp\lib\site-packages\numpy\core\multiarray.py",line 12,in <module>
from . import overrides
File "C:\Conda\envs\gcp\lib\site-packages\numpy\core\overrides.py",line 7,in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load Failed while importing _multiarray_umath: The specified module Could not be found.

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
File "c:\API\citi-bike.py",line 4,in <module>
import numpy as np
File "C:\Conda\envs\gcp\lib\site-packages\numpy\__init__.py",line 150,in <module>
from . import core
File "C:\Conda\envs\gcp\lib\site-packages\numpy\core\__init__.py",line 48,in <module>
raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions Failed. This error can happen for
many reasons,often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

* The Python version is: python3.9 from "C:\Conda\envs\gcp\python.exe"
* The NumPy version is: "1.21.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load Failed while importing _multiarray_umath: The specified module Could not be found.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Arrays.sort() VS Arrays.parallelSort()

Arrays.sort() VS Arrays.parallelSort()

英文原文地址:Arrays.sort vs Arrays.parallelSort

翻译:高行行

1. 概述

我们都使用过 Arrays.sort() 对对象或原始数据类型数组(byteshortintlongcharfloatdoubleboolean)进行排序。在 JDK 8 中,创造者增强了 API 以提供一种新方法:Arrays.parallelSort()

在本教程中,我们将对 sort() 和 parallelSort() 方法进行比较。

2. Arrays.sort()

Arrays.sort() 方法对对象或原始数据类型的数组进行排序。此方法中使用的排序算法是 Dual-Pivot Quicksort。 换句话说,它是快速排序算法的自定义实现,以实现更好的性能。

此方法是单线程的 ,有两种变体:

  • sort(array)–将整个数组按升序排序
  • sort(array, fromIndex, toIndex)–仅将从 fromIndex 到 toIndex 的元素排序

让我们看一下两种变体的例子:

@Test
public void givenArrayOfIntegers_whenUsingArraysSortMethod_thenSortFullArrayInAscendingOrder() {
    int[] array = { 10, 4, 6, 2, 1, 9, 7, 8, 3, 5 };
    int[] expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 
    Arrays.sort(array);
 
    assertArrayEquals(expected, array);
 
}
 
@Test
public void givenArrayOfIntegers_whenUsingArraysSortMethodWithRange_thenSortRangeOfArrayInAscendingOrder() {
    int[] array = { 10, 4, 6, 2, 1, 9, 7, 8, 3, 5 };
    int[] expected = { 10, 4, 1, 2, 6, 7, 8, 9, 3, 5 };
 
    Arrays.sort(array, 2, 8);
 
    assertArrayEquals(expected, array);
}

让我们总结一下这种方法的优缺点:

优点 缺点
快速处理较小的数据集 大型数据集的性能下降
没有利用系统的多个核心

3. Arrays.parallelSort()

此方法对对象或原始数据类型的数组进行排序。与 sort() 类似,它也有两个变体来对完整数组和部分数组进行排序:

@Test
public void givenArrayOfIntegers_whenUsingArraysParallelSortMethod_thenSortFullArrayInAscendingOrder() {
    int[] array = { 10, 4, 6, 2, 1, 9, 7, 8, 3, 5 };
    int[] expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 
    Arrays.parallelSort(array);
 
    assertArrayEquals(expected, array);
}
 
@Test
public void givenArrayOfIntegers_whenUsingArraysParallelSortMethodWithRange_thenSortRangeOfArrayInAscendingOrder() {
    int[] array = { 10, 4, 6, 2, 1, 9, 7, 8, 3, 5 };
    int[] expected = { 10, 4, 1, 2, 6, 7, 8, 9, 3, 5 };
 
    Arrays.parallelSort(array, 2, 8);
 
    assertArrayEquals(expected, array);
}

parallelSort() 在功能上有所不同。与 sort() 使用单个线程对数据进行顺序排序不同,它使用并行排序-合并排序算法。它将数组分成子数组,这些子数组本身先进行排序然后合并。

为了执行并行任务,它使用 ForkJoin 池。

但是我们需要知道,只有在满足某些条件时,它才会使用并行性。如果数组大小小于或等于 8192,或者处理器只有一个核心,则它将使用顺序的 Dual-Pivot Quicksort 算法。否则,它使用并行排序。

让我们总结一下使用它的优缺点:

优点 缺点
为大型数据集提供更好的性能 对于大小较小的数组,处理速度较慢
利用系统的多个核心

4.比较

现在,让我们看看在不同大小的数据集上两种方法怎样执行。以下数字是使用JMH 基准测试得出的。测试环境使用 AMD A10 PRO 2.1Ghz 四核处理器和 JDK 1.8.0_221:

数组大小 Arrays.sort() Arrays.parallelSort()
1000 o.048 0.054
10000 0.847 0.425
100000 7.570 4.395
1000000 65.301 37.998

5.结论

在这篇快速文章中,我们看到了 sort() 和 parallelSort() 的不同之处。

根据性能结果,我们可以得出结论,当我们要排序的数据集很大时,parallelSort() 可能是更好的选择。但是,在数组较小的情况下,最好使用 sort(),因为它可以提供更好的性能。

与往常一样,完整的源代码可以在 GitHub 找到。

个人公众号《骇客与画家》,欢迎关注

Code Hunt SECTOR 10 - 11(Jagged Arrays & Arrays 2)

Code Hunt SECTOR 10 - 11(Jagged Arrays & Arrays 2)

1. 关于本博客的说明

Code Hunt 是我从 CSDN 上的一篇文章中无意间看到的:微软研究院正式发布编程学习游戏 Code Hunt,游戏地址从这里进入。

本篇博客是游戏的 JAGGED ARRAYS 和 Arrays 2 部分的 C# 部分解题代码

2.SECTOR10:JAGGED ARRAYS

1)SECTOR10-01

SKILL RATING:3

using System;
public class Program
{
    public static int Puzzle(int[][] listint i, int j)
    {
        return list[i][j];
    }
}

2)SECTOR10-02

SKILL RATING:1

建立一个大小为 5*5 的矩阵,每个元素赋初值为 0

using System;
public class Program
{
    public static int[][] Puzzle()
    {
        return new int[][] { new int[5], new int[5], new int[5], new int[5], new int[5] };
    }
}

3)SECTOR10-03

建立一个大小为 length*length 的矩阵,每个元素赋初值为 x

SKILL RATING:1

using System;
public class Program
{
    public static int[][] Puzzle(int length, int x)
    {
        int[] array = new int[length];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = x; 
        }
        int[][] result = new int[length][];
        for (int i = 0; i < result.Length; i++)
        { 
            result[i] = array; 
        }
        return result;
    }
}

4)SECTOR10-04

SKILL RATING:3

using System;
public class Program
{
    public static int[][] Puzzle(int[][] input)
    {
        int[][] result = new int[input.Length][];
        for (int i = 0; i result.Lengthi++)
        {
            result[i] = new int[input[i].Length];
            for (int j = 0; j < result[i].Lengthj++)
            {
                result[i][j] = input[i][j] * 2;
            }
        }
        return result;
    }
}

SKILL RATING:?

using System;
public class Program
{
    public static int[][] Puzzle(int[][] input)
    {
        for (int i = 0; i input.Lengthi++)
        {
            for (int j = 0; j < input[i].Lengthj++)
            {
                input[i][j] *= 2;
            }
        }
        return input;
    }
}

5)SECTOR10-05

找出数组 input 中等于 i 的元素个数

SKILL RATING:3

using System;
public class Program
{
    public static int Puzzle(int[][] input, int i)
    {
        int counter = 0;
        for (int x = 0; x < input.Length; x++)
        {
            for (int y = 0; y < input[x].Length; y++)
            {
                if (input[x][y] == i)
                {
                    counter++;
                }
            }
        }
        return counter;
    }
}

6)SECTOR10-06

SKILL RATING:1

using System;
public class Program
{
    public static int Puzzle(int[][] input)
    {
        int max = int.MinValue;
        for (int x = 0; x < input.Length; x++)
        {
            for (int y = 0; y < input[x].Length; y++)
            {
                if (input[x][y] > max)
                {
                    max = input[x][y];
                }
            }
        }
        return max;
    }
}

7)SECTOR10-07

找到锯齿型数组中和最大的一个元素数组

SKILL RATING:2

using System;
public class Program
{
    public static int[] Puzzle(int[][] input)
    {
        int maxsum = int.MinValue;
        int arrsum = 0;
        int isign = 0;
        for (int i = 0; i < input.Length; i++)
        {
            arrsum = 0;
            for (int j = 0; j < input[i].Length; j++)
            {
                arrsum += input[i][j];
            }
            if (arrsum > maxsum)
            {
                maxsum = arrsum;
                isign = i;
            }
        }
        return input[isign];
    }
}

8)SECTOR10-08

找出二维数组各列中元素总和最大的列,并输出该列各元素和

SKILL RATING:2

using System;
public class Program
{
    public static int Puzzle(int[][] input)
    {
        int[] arrsum = new int[input[0].Length];
        int sum = 0;
        for (int i = 0; i < input[0].Length; i++)
        {
            sum = 0;
            for (int j = 0; j < input.Length; j++)
            {
                sum += input[j][i];
            }
            arrsum[i] = sum;
        }

        int max = int.MinValue;
        int sign = 0;
        for (int x = 0; x < arrsum.Length; x++)
        {
            if (arrsum[x] > max)
            {
                max = arrsum[x];
                sign = x;
            }
        }

        return arrsum[sign];
    }
}

SKILL RATING:3

using System;
public class Program
{
    public static int Puzzle(int[][] input)
    {
        int max = int.MinValue;
        int sum = 0;

        for (int i = 0; i < input[0].Length; i++)
        {
            sum = 0;
            for (int j = 0; j < input.Length; j++)
            {
                sum += input[j][i];
            }
            if (max < sum)
            {
                max = sum;
            }
        }
        return max;
    }
}

2.SECTOR11:ARRAYS 2

1)SECTOR11-01

两个数组 a,b 生成一个新的数组 c
c [i]=a [i]-b [i] (i<a、b 的长度,且 a [i]>=b [i])
c [i]=b [i]-a [i] (i<a、b 的长度,且 a [i]<b [i])
c [i]=0-b [i] (i>=a 的长度且 i<b 的长度)
c [i]=a [i]-0 (i>=b 的长度且 i<a 的长度)

SKILL RATING:1

using System;
public class Program
{
    public static int[] Puzzle(int[] a, int[] b)
    {
        int[] c = new int[a.Length >= b.Length ? a.Length : b.Length];
        for (int i = 0; i < c.Length; i++)
        {
            if (i < a.Length && i < b.Length)
            {
                c[i] = a[i] >= b[i] ? a[i] - b[i] : b[i] - a[i];
            }
            else if (i >= a.Length && i < b.Length)
            {
                c[i] = 0 - b[i];
            }
            else
            {
                c[i] = a[i] - 0;
            }
        }

        return c;
    }
}

2)SECTOR11-02

将一个数组中每个元素复制一个放在自己后面,生成一个新数组

{"", "a"} → {"", "", "a", "a"}

SKILL RATING:2

using System;
public class Program
{
    public static string[] Puzzle(string[] a, int amount)
    {
        string[] s = new string[a.Length * amount];
        for (int i = 0; i < a.Length; i++)
        {
            for (int j = 0; j < amount; j++)
            {
                s[amount * i + j] = a[i];
            }
        }
        return s;
    }
}

3)SECTOR11-03

一个二维方阵,判断两个对角线元素和是否相等

SKILL RATING:3

using System;
public class Program
{
    public static bool Puzzle(int[][] input)
    {
        int sum1 = 0, sum2 = 0;
        for (int i = 0; i < input.Length; i++)
        {
            sum1 += input[i][i];
            sum2 += input[i][input.Length - 1 - i];
        }
        return sum1 == sum2 ? true : false;
    }
}

4)SECTOR11-04

SKILL RATING:3

using System;
public class Program
{
    public static int[] Puzzle(int[] listint modBy)
    {
        for (int i = 0; i < list.Length; i++)
        {
            list[i] %= modBy;
        }
        return list;
    }
}

5)SECTOR11-05

SKILL RATING:2

using System;
public class Program {
    public static string[] Puzzle(string[] list) 
    {
        string[] result = new string[(list.Length+1)/2];
        for(int i=0;i<result.Length-1;i++)
        {
            result[i]=list[i*2]+list[i*2+1];
        }
        result[result.Length-1] = (list.Length%2==0)?
            (list[list.Length-2]+list[list.Length-1]):(list[list.Length-1]);
        return result;
    }
}

6)SECTOR11-06

SKILL RATING:3

using System;
public class Program
{
    public static string[] Puzzle(int[] grades, int A, int B, int C, int D)
    {
        string[] sgrades = new string[grades.Length];
        for (int i = 0; i < grades.Length; i++)
        {
            sgrades[i] = (
                grades[i] >= A ? "A" : (
                    grades[i] >= B ? "B" : (
                        grades[i] >= C ? "C" : (
                            grades[i] >= D ? "D" : "E"))));
        }
        return sgrades;
    }
}

7)SECTOR11-07

SKILL RATING:3

using System;
public class Program
{
    public static string[][] Puzzle(string[][] input)
    {
        string temp;
        for (int i = 0; i < input.Length; i++)
        {
            for (int j = i; j < input[i].Length; j++)
            {
                temp = input[i][j];
                input[i][j] = input[j][i];
                input[j][i] = temp;
            }
        }
        return input;
    }
}


cvxpy 和 numpy 之间的版本冲突:“针对 API 版本 0xe 编译的模块,但此版本的 numpy 是 0xd”

cvxpy 和 numpy 之间的版本冲突:“针对 API 版本 0xe 编译的模块,但此版本的 numpy 是 0xd”

如何解决cvxpy 和 numpy 之间的版本冲突:“针对 API 版本 0xe 编译的模块,但此版本的 numpy 是 0xd”?

我正在尝试升级一些软件包并为现有的 Python 程序整合我的 requirements.txt,以便将其移至 docker 容器。

这个容器将基于 tensorflow docker 容器,这决定了我必须使用的一些包版本。我们在 windows 下工作,我们希望能够在我们的机器上本地运行该程序(至少在一段时间内)。所以我需要找到一个适用于 docker 和 Windows 10 的配置。

Tensorflow 2.4.1 需要 numpy~=1.19.2。使用 numpy 1.20 时,pip 会抱怨 numpy 1.20 是一个不兼容的版本。

但是在使用 numpy~=1.19.2 时,导入 cvxpy 时出现以下错误。 pip 安装所有软件包都很好:

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
Traceback (most recent call last):
  File "test.py",line 1,in <module>
    import cvxpy
  File "c:\Projekte\algo5\venv\lib\site-packages\cvxpy\__init__.py",line 18,in <module>
    from cvxpy.atoms import *
  File "c:\Projekte\algo5\venv\lib\site-packages\cvxpy\atoms\__init__.py",line 20,in <module>
    from cvxpy.atoms.geo_mean import geo_mean
  File "c:\Projekte\algo5\venv\lib\site-packages\cvxpy\atoms\geo_mean.py",in <module>
    from cvxpy.utilities.power_tools import (fracify,decompose,approx_error,lower_bound,File "c:\Projekte\algo5\venv\lib\site-packages\cvxpy\utilities\power_tools.py",in <module>
    from cvxpy.atoms.affine.reshape import reshape
  File "c:\Projekte\algo5\venv\lib\site-packages\cvxpy\atoms\affine\reshape.py",in <module>
    from cvxpy.atoms.affine.hstack import hstack
  File "c:\Projekte\algo5\venv\lib\site-packages\cvxpy\atoms\affine\hstack.py",in <module>
    from cvxpy.atoms.affine.affine_atom import AffAtom
  File "c:\Projekte\algo5\venv\lib\site-packages\cvxpy\atoms\affine\affine_atom.py",line 22,in <module>
    from cvxpy.cvxcore.python import canonInterface
  File "c:\Projekte\algo5\venv\lib\site-packages\cvxpy\cvxcore\python\__init__.py",line 3,in <module>
    import _cvxcore
ImportError: numpy.core.multiarray Failed to import

重现步骤:

1.) 在 Windows 10 下创建一个新的 Python 3.8 venv 并激活它

2.) 通过 requirements.txt 安装以下 pip install -r requirements.txt

cvxpy 
numpy~=1.19.2 # tensorflow 2.4.1 requires this version

3.) 通过 test.py

执行以下 python test.py
import cvxpy

if __name__ == ''__main__'':
    pass

如果我想使用 tensorflow 2.3,也会发生同样的事情。在这种情况下需要 numpy~=1.18,错误完全相同。

搜索错误发现很少的命中,可悲的是没有帮助我。

我该怎么做才能解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

今天的关于Numpy nanargmin和nanargmax不适用于datetime-arraysnumpy.ndarray is not callable的分享已经结束,谢谢您的关注,如果想了解更多关于Anaconda Numpy 错误“Importing the Numpy C Extension Failed”是否有另一种解决方案、Arrays.sort() VS Arrays.parallelSort()、Code Hunt SECTOR 10 - 11(Jagged Arrays & Arrays 2)、cvxpy 和 numpy 之间的版本冲突:“针对 API 版本 0xe 编译的模块,但此版本的 numpy 是 0xd”的相关知识,请在本站进行查询。

本文标签: