GVKun编程网logo

构建 Fortran/Numpy 扩展时不完整的 python 源代码分布(numpy.frombuffer)

1

关于构建Fortran/Numpy扩展时不完整的python源代码分布和numpy.frombuffer的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于"importnumpyasnp"I

关于构建 Fortran/Numpy 扩展时不完整的 python 源代码分布numpy.frombuffer的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于"import numpy as np" ImportError: No module named numpy、3.7Python 数据处理篇之 Numpy 系列 (七)---Numpy 的统计函数、AMD 推出 GPUFORT:Fortran+OpenACC 和 CUDA Fortran 的源到源转换、Difference between import numpy and import numpy as np等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

构建 Fortran/Numpy 扩展时不完整的 python 源代码分布(numpy.frombuffer)

构建 Fortran/Numpy 扩展时不完整的 python 源代码分布(numpy.frombuffer)

如何解决构建 Fortran/Numpy 扩展时不完整的 python 源代码分布

在构建包含 Fortran/Numpy 扩展的 Python 包的源代码分发时,源代码分发是不完整的。它缺少源文件 fortranobject.cfortranobject.h,当您执行 二进制 构建 (setup) 时,它们由 numpy 自己的 bdist 函数复制,或本地安装。但是,如果您执行 source 构建 (sdist),则不会打包这些文件。因此,源代码分发不能用于本地构建二进制轮,因此本地安装也会失败。

最初,我将此报告为 pypa/build 中的错误(请参阅:https://github.com/pypa/build/issues/326)。但是,我认为问题在于 numpy,而不是 pypa/build,因为当您执行传统的 python setup.py build_ext sdist 来构建源代码分发时会出现同样的问题。

有人知道如何解决这个问题吗?

解决方法

好的,我终于找到了这个问题,我认为这是 Numpy 的 Extension 中的 distutils 如何处理 pyf 源文件的错误。这是错误报告:https://github.com/numpy/numpy/issues/19441。

"import numpy as np" ImportError: No module named numpy

问题:没有安装 numpy

解决方法:

下载文件,安装

numpy-1.8.2-win32-superpack-python2.7

安装运行 import numpy,出现

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    import numpy
  File "C:\Python27\lib\site-packages\numpy\__init__.py", line 153, in <module>
    from . import add_newdocs
  File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 6, in <module>
    from . import multiarray
ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。

原因是:python 装的是 64 位的,numpy 装的是 32 位的

重新安装 numpy 为:numpy-1.8.0-win64-py2.7

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3.7Python 数据处理篇之 Numpy 系列 (七)---Numpy 的统计函数

3.7Python 数据处理篇之 Numpy 系列 (七)---Numpy 的统计函数

目录

[TOC]

前言

具体我们来学 Numpy 的统计函数

(一)函数一览表

调用方式:np.*

.sum(a) 对数组 a 求和
.mean(a) 求数学期望
.average(a) 求平均值
.std(a) 求标准差
.var(a) 求方差
.ptp(a) 求极差
.median(a) 求中值,即中位数
.min(a) 求最大值
.max(a) 求最小值
.argmin(a) 求最小值的下标,都处里为一维的下标
.argmax(a) 求最大值的下标,都处里为一维的下标
.unravel_index(index, shape) g 根据 shape, 由一维的下标生成多维的下标

(二)统计函数 1

(1)说明

(2)输出

.sum(a)

.mean(a)

.average(a)

.std(a)

.var(a)

(三)统计函数 2

(1)说明

(2)输出

.max(a) .min(a)

.ptp(a)

.median(a)

.argmin(a)

.argmax(a)

.unravel_index(index,shape)

作者:Mark

日期:2019/02/11 周一

AMD 推出 GPUFORT:Fortran+OpenACC 和 CUDA Fortran 的源到源转换

AMD 推出 GPUFORT:Fortran+OpenACC 和 CUDA Fortran 的源到源转换

Phoronix 消息指出,AMD 现已经向一个名为 GPUFORT 的新项目公开了他们的代码。这个新的 GPUFORT 项目将处在 Radeon Open eCosystem(ROCm)的保护伞下,是他们在帮助拥有大型 CUDA 代码库的开发者从 NVIDIA 的封闭生态系统中进行过渡所做的最新努力。

过去几年的时间里,AMD 已经做出了 HIPify 和其他方面努力,以帮助开发人员将尽可能多的 CUDA 特定代码迁移到 Radeon 开源计算堆栈支持的接口。迄今为止,这些努力大部分都集中在 C/C++ 代码上,而 GPUFORT 则是采用以 CUDA 为中心的 Fortran 代码并将其调整为 Radeon GPU 执行。GPUFORT 支持将 CUDA Fortran 和基于 OpenACC 的 Fortran 代码的源代码转换为 OpenMP 4.5+ 以供 GPU 执行或 Fortran + HIP C++ 代码。

根据介绍,GPUFORT 是一个研究项目,不是编译器本身,而是执行源到源转换的 Python 代码库。至少在目前的这个阶段,AMD 工程师并不指望 GPUFORT 能够创建一个完全有效的自动化解决方案;但对于更复杂的代码库来说,可能需要对自动生成的代码进行一些手动审查和修复。

目前,GPUFORT 开发人员已经成功地使用该工具将各种现实世界的 HPC 软件转换为 OpenMP Fortran/HIP C++ 代码,并取得了成功 —— 相对于原来 NVIDIA 注重的 Fortran 代码而言,性能变得更强。

AMD 已经在 MIT 许可下公开了 GPUFORT 的代码。

Difference between import numpy and import numpy as np

Difference between import numpy and import numpy as np

Difference between import numpy and import numpy as np

up vote 18 down vote favorite

5

I understand that when possible one should use

import numpy as np

This helps keep away any conflict due to namespaces. But I have noticed that while the command below works

import numpy.f2py as myf2py

the following does not

import numpy as np
np.f2py #throws no module named f2py

Can someone please explain this?

python numpy

shareimprove this question

edited Mar 24 ''14 at 23:20

mu 無

24.7k104471

asked Mar 24 ''14 at 23:19

user1318806

3001311

 
1  

@roippi have you tried exit your python and enter it and just do import numpy then numpy.f2py ? It throws an error in my case too – aha Mar 24 ''14 at 23:24

1  

Importing a module doesn''t import sub-modules. You need to explicitly import the numpy.f2py module regardless of whether or not/how numpy itself has been imported. – alecb Mar 24 ''14 at 23:39

add a comment

4 Answers

active oldest votes

 

up vote 13 down vote

numpy is the top package name, and doing import numpy doesn''t import submodule numpy.f2py.

When you do import numpy it creats a link that points to numpy, but numpy is not further linked to f2py. The link is established when you do import numpy.f2py

In your above code:

import numpy as np # np is an alias pointing to numpy, but at this point numpy is not linked to numpy.f2py
import numpy.f2py as myf2py # this command makes numpy link to numpy.f2py. myf2py is another alias pointing to numpy.f2py as well

Here is the difference between import numpy.f2py and import numpy.f2py as myf2py:

  • import numpy.f2py
    • put numpy into local symbol table(pointing to numpy), and numpy is linked to numpy.f2py
    • both numpy and numpy.f2py are accessible
  • import numpy.f2py as myf2py
    • put my2py into local symbol table(pointing to numpy.f2py)
    • Its parent numpy is not added into local symbol table. Therefore you can not access numpy directly

shareimprove this answer

edited Mar 25 ''14 at 0:31

answered Mar 24 ''14 at 23:33

aha

1,2291718

 

add a comment

 

up vote 7 down vote

The import as syntax was introduced in PEP 221 and is well documented there.

When you import a module via

import numpy

the numpy package is bound to the local variable numpy. The import as syntax simply allows you to bind the import to the local variable name of your choice (usually to avoid name collisions, shorten verbose module names, or standardize access to modules with compatible APIs).

Thus,

import numpy as np

is equivalent to,

import numpy
np = numpy
del numpy

When trying to understand this mechanism, it''s worth remembering that import numpy actually means import numpy as numpy.

When importing a submodule, you must refer to the full parent module name, since the importing mechanics happen at a higher level than the local variable scope. i.e.

import numpy as np
import numpy.f2py   # OK
import np.f2py      # ImportError

I also take issue with your assertion that "where possible one should [import numpy as np]". This is done for historical reasons, mostly because people get tired very quickly of prefixing every operation with numpy. It has never prevented a name collision for me (laziness of programmers actually suggests there''s a higher probability of causing a collision with np)

Finally, to round out my exposé, here are 2 interesting uses of the import as mechanism that you should be aware of:

1. long subimports

import scipy.ndimage.interpolation as warp
warp.affine_transform(I, ...)

2. compatible APIs

try:
    import pyfftw.interfaces.numpy_fft as fft
except:
    import numpy.fft as fft
# call fft.ifft(If) with fftw or the numpy fallback under a common name

shareimprove this answer

answered Mar 25 ''14 at 0:59

hbristow

68345

 

add a comment

 

up vote 1 down vote

numpy.f2py is actually a submodule of numpy, and therefore has to be imported separately from numpy. As aha said before:

When you do import numpy it creats a link that points to numpy, but numpy is not further linked to f2py. The link is established when you do import numpy.f2py

when you call the statement import numpy as np, you are shortening the phrase "numpy" to "np" to make your code easier to read. It also helps to avoid namespace issues. (tkinter and ttk are a good example of what can happen when you do have that issue. The UIs look extremely different.)

shareimprove this answer

answered Mar 24 ''14 at 23:47

bspymaster

760923

 

add a comment

 

up vote 1 down vote

This is a language feature. f2py is a subpackage of the module numpy and must be loaded separately.

This feature allows:

  • you to load from numpy only the packages you need, speeding up execution.
  • the developers of f2py to have namespace separation from the developers of another subpackage.

Notice however that import numpy.f2py or its variant import numpy.f2py as myf2py are still loading the parent module numpy.

Said that, when you run

import numpy as np
np.f2py

You receive an AttributeError because f2py is not an attribute of numpy, because the __init__() of the package numpy did not declare in its scope anything about the subpackage f2py.

shareimprove this answer

answered Mar 24 ''14 at 23:57

gg349

7,67321739

 
    

when you do import numpy.f2py as myf2py, how do you access its parent numpy? it seems import numpy.f2py allows you to access its parent numpy, but import numpy.f2py as myf2py doesn''t – aha Mar 25 ''14 at 0:00

    

You don''t access it because you decided you didn''t want to use anything from numpy, and you only care of using the subpackage. It is similar to using from foo import bar: the name foo will not be accessible. See the comment after the first example of the docs, LINK – gg349 Mar 25 ''14 at 0:05

add a comment

今天的关于构建 Fortran/Numpy 扩展时不完整的 python 源代码分布numpy.frombuffer的分享已经结束,谢谢您的关注,如果想了解更多关于"import numpy as np" ImportError: No module named numpy、3.7Python 数据处理篇之 Numpy 系列 (七)---Numpy 的统计函数、AMD 推出 GPUFORT:Fortran+OpenACC 和 CUDA Fortran 的源到源转换、Difference between import numpy and import numpy as np的相关知识,请在本站进行查询。

本文标签: