Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Andrew Murray
    @radarhere
    Ok, so currently only RecursionError and MemoryError will be raised as errors, yes, I can verify that they do raise.
    How does __array__ relate?
    Andrew Murray
    @radarhere
    __array__ seems to have the same error catching as __array_interface__.
    You're not suggesting using a custom array container instead of just np.array?
    Sebastian Berg
    @seberg
    @radarhere __array__ is not a property, I don't think that is true in general, although possibly for the attribute access itself
    Andrew Murray
    @radarhere
    Ah, ok, thanks
    Nico Schlömer
    @nschloe
    After installing numpy from master (pip install .), import numpy gives me No module named 'numpy.random._bit_generator'. Any idea what I'm doing wrong?
    Nico Schlömer
    @nschloe
    Okay, cleaned up the build dir (git -dfx), not it works
    Chris Meyer
    @cmeyer1969:matrix.org
    [m]

    I'm wondering if there is a way to use an index array with shape m x n to index into another array of shape m x n x p.

    For instance, if I have the code below, is there any way to get d[y,x,i[y,x]] for all y,x without explicitly iterating? The result would be a 2x2 array in the code below.

    >>> i = numpy.array([[0,1],[2,3]])
    >>> d = numpy.random.randn(2,2,4)
    >>> d[1,0,i[1,0]]
    1.5512465367574528
    In practice, this can arise after using numpy.argmax(..., axis=0) and then wanting to get the actual max value using the resulting indexes.
    Angus Hollands
    @agoose77:matrix.org
    [m]
    I think you want take_along_axis
    Chris Meyer
    @cmeyer1969:matrix.org
    [m]
    That's it. Thanks.
    leonardojimenez1990
    @leonardojimenez1990

    hello, how can i read this data correctly?

    ncfile = Dataset("wrfout_d01_2021-04-11_00:00:00")
    ncfile["Times"][0]

    <ipython-input-42-0be7531eb713>:12: DeprecationWarning: np.bool is a deprecated alias for the builtin bool. To silence this warning, use bool by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.bool_ here.
    Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    ncfile["Times"][0]

    maskedarray(data=[b'2', b'0', b'2', b'1', b'-', b'0', b'4', b'-', b'1',
    b'1', b'
    ', b'0', b'0', b':', b'0', b'0', b':', b'0',
    b'0'],
    mask=False,
    fill_value=b'N/A',
    dtype='|S1')

    Angus Hollands
    @agoose77:matrix.org
    [m]
    What do you mean correctly?
    leonardojimenez1990
    @leonardojimenez1990

    without the numpy 1.20 warning.

    <ipython-input-42-0be7531eb713>:12: DeprecationWarning: np.bool is a deprecated alias for the builtin bool. To silence this warning, use bool by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.bool_ here.
    Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    ncfile["Times"][0]

    Angus Hollands
    @agoose77:matrix.org
    [m]
    It's not clear what your Dataset object is. It looks like the code you're using to load this data set is using np.bool instead of np.bool_ or bool
    leonardojimenez1990
    @leonardojimenez1990
    @agoose77:matrix.org Ah, ok, thanks
    Ronnie Gandhi
    @RonnieGandhi

    Hello Team,

    I am Ronnie Gandhi, a Computer Science undergrad from IIT Roorkee in my final year. I am interested in working on the problem statement of NumPy in this GSoD2021

    I have successfully completed GSoD2020(my display name is Krezhairo) under LibreOffice, I have done GSoC 2019 , and 2020 under CGAL, and I have been contributing to open-source development for quite a while.

    I have also done a Data Science internship at Microsoft, Hyderabad in 2019 and 2020.

    I am very well versed with Python,and Jupyter Notebooks, and of course CLI tools. Also from my past GSoD2020 experience I know Markdown, reStructuredText, Sphinx as well.

    Daniel Pinyol
    @dpinol
    Hi, has anybody used the numpy plugin? If I add plugins = numpy.typing.mypy_plugin to mypy.ini, I get Error importing plugin 'numpy.typing.mypy_plugin': No module named 'numpy.typing'
    Chris Angelico
    @Rosuav
    Hi! Running into a problem with numpy on Debian Buster. I have multiple CPythons installed, but as far as I know, nothing touches the system Python.
    Python, numpy, and everything that's trying to work on top of numpy (pandas, plotly), all installed via apt. Attempting to import numpy gives a noisy ImportError, saying "Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy."
    sys.path ==> ['', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/home/rosuav/.local/lib/python3.5/site-packages', '/usr/local/lib/python3.5/dist-packages', '/usr/local/lib/python3.5/dist-packages/snowboy-1.3.0-py3.5.egg', '/usr/lib/python3/dist-packages']
    This is Debian GNU/Linux version 10, "Buster".
    Thomas Aarholt
    @thomasaarholt
    @dpinol my guess is that you're using an older version of numpy. .typing was introduced in 1.20
    Takahiro Ueda
    @tueda

    For the mypy plugin, I also have the same problem (No module named 'numpy.typing.mypy_plugin'). Actually, I don't see numpy/typing/mypy_plugin.py in the installed package.

    Environment: Python 3.9.4, CentOS 7, x86_64:

    > pip list
    Package           Version
    ----------------- --------
    mypy              0.812
    mypy-extensions   0.4.3
    numpy             1.20.2
    pip               21.0.1
    setuptools        54.2.0
    typed-ast         1.4.3
    typing-extensions 3.10.0.0
    
    > ls .venv/lib/python3.9/site-packages/numpy/typing
    __pycache__/  __init__.py        _array_like.py  _dtype_like.py  _shape.py
    tests/        _add_docstring.py  _callable.py    _scalars.py     setup.py
    agoose77
    @agoose77:matrix.org
    [m]
    @tueda: I don't think this plugin has been released yet; it's only in main on GitHuvb
    Takahiro Ueda
    @tueda
    @agoose77:matrix.org Oh, you are right. I was looking at the devdocs, which I found by googling without thinking. Thanks.
    Angus Hollands
    @agoose77:matrix.org
    [m]
    @tueda I've been bitten a few too many times with this when reading various libraries that I now assume they're out of sync 😂
    Christopher Dignam
    @chdsbd

    I have a question about type annotations with numpy.

    I have a function that takes a Sequence of floats. How can I type my numpy array such that it can meet the Sequence protocol?

    from typing import Sequence
    
    import numpy as np
    
    def process(x: Sequence[float]) -> None: ...
    
    my_array = np.empty(10, np.float16)
    process(my_array)
    # mypy: Argument 1 to "process" has incompatible type "ndarray"; expected "Sequence[float]"  [arg-type]
    1 reply
    sir-ion
    @sir-ion

    Hi everyone, I am learning numpy from scratch right now and I have a (possibily very dumb) question. The most common(?) way to build a numpy array is the following: np.array([i for i in range(1_000_000)]); however - if I am not wrong - this loads the array twice in memory: once when the list comprehension [...] is executed and once when the ndarray object is built (which copies the content of the python list in a "self-managed" area of the memory, if I well understood the docs). If this is true is, there a way to avoid the use of twice the memory?

    Related question: I noticed that if I feed a generator to the np.array() function (e.g. np.array(i for i in custom_generator())) the generator object itself is used as a single element for the array (and elements "inside" the generator are not "extracted"). Why? Maybe because a generator does not allow to know its length a priori?

    Angus Hollands
    @agoose77:matrix.org
    [m]
    @sir-ion: NumPy has some constructor functions such as np.zeros(...), np.ones(...), etc., which can be used to generate arrays of a given length full of zeros or ones,
    1 reply
    Jody Klymak
    @jklymak
    @sir-ion you almost never need to use list comprehension: np.arange(1_000_000), np.asarray(my_list_of_numbers)
    DJMO3
    @DJMO3
    Hey everyone, I'm having the famous DLL not loaded error. I'm using conda environments and I already reinstalled numpy (at the expense of my environment dependencies on numpy). I've had this issue before and found out that the problem was with libiomp5md.dll which was found both in my venv folder and in my System 32 folder (yes I am using windows). At first I just copied the DLL file from the venv folder and pasted it in system 32 and everything worked like magic. But anyway, how do you suggest we deal with this issue? What causes it and what can be done to prevent it?
    kyle-source
    @kyle-source
    Hey everyone,I have a question about how to install numpy by Macbook M1 ,my python is 3.9
    Thomas Aarholt
    @thomasaarholt
    Have you tried installing via pip? One of the answers (8th of May) in this thread suggests installing from source, as there seems to have been a fix submitted: https://stackoverflow.com/questions/65336789/numpy-build-fail-in-m1-big-sur-11-1
    How have you tried installing it? If conda / pip install numpy doesn't work, try:
    pip install https://github.com/numpy/numpy/archive/refs/heads/main.zip
    dittid
    @dittid:matrix.org
    [m]
    :point_up: Edit: I know dusk does something similar, but it implements it as parallelized operations on graphs. I was thinking maybe more on an architecture based on MPI.
    :point_up: Edit: I know dask does something similar, but it implements it as parallelized operations on graphs. I was thinking maybe more on an architecture based on MPI.
    Adam Ginsburg
    @keflavich
    I have an f2py question. I have some old code that just stopped working with recent versions of f2py, though I can't say when. The problem is that f2py is treating a character*120 as some... hard to understand hybrid between a byte array and a string. I can assign it a string, but it gets stored as bytes. e.g.:
    ipdb> self.radex.impex.molfile = 'abcdef'+114*" "
    ipdb> self.radex.impex.molfile
    array(b'abcdef                                                                                                                  ',
          dtype='|S120')
    and when the underlying fortran code reads that, I think it's seeing the b' as part of the string.
    I don't know how to produce an MWE for this, though.
    Adam Ginsburg
    @keflavich
    nah, nevermind, that was a red herring.
    Melissa Weber Mendonça
    @melissawm
    Hi @keflavich, there are indeed a few issues related to string support in f2py. Can you check our issue tracker to see if this has been addressed in any of those issues? If not, I can take a look and it is entirely possible we will have to file a new issue. Thanks!
    Adam Ginsburg
    @keflavich
    Thanks Melissa! I figured out where the problem lies, but I don't know how to diagnose it - it turns out not to be a string error, but an array error. In the fortran code, as soon as I try to access an array (e.g., arr(1,2,3)), it triggers a segfault. I'll look through the issues
    @melissawm do you have any tips on how to diagnose more accurately - i.e., determine whether my issue is covered by one of the open issues?
    Adam Ginsburg
    @keflavich
    the open issue, which I may need to push upstream, is keflavich/pyradex#34
    Melissa Weber Mendonça
    @melissawm
    Hey @keflavich if you want to continue debugging here I can try and help you later today. If we do run into issues we'll move to github
    Adam Ginsburg
    @keflavich
    Thanks. At the moment... I really don't know where the issue lies, and I probably can't put more time into debugging it today. The problem I solved years ago was wrapping RADEX, a venerable fortran modeling code, with f2py for direct use in python, and something about what I had done is broken now
    Andrew Nelson
    @andyfaff
    I have a quick question. Why doesn't this assertion hold?
    import numpy as np
    a = np.linspace(0.01, 0.1, 100).reshape(50, 2)
    b = np.full_like(a, True, dtype=bool)
    assert a.shape == b.shape
    assert a[b].shape == a.shape
    Hold on, I think I see the issue. If one sets b[0, 1] = False, then how can a[b] still be 2 dimensional.