Skip to content

Feature request: fromstring to read complex array #13891

Closed

Description

@ogauthe

Hello,

np.fromstring is not able to process complex data type. This would be useful to read from text input file. At least the documentation should mention that complex is not accepted as dtype.

Reproducing code example:

import numpy as np
s = '1+0.4j, 0.5j, 0.6j, 0.3j'
np.fromstring(s, sep=',', dtype=complex)

Error message:

ValueError: don't know how to read character strings with that array type

In case someone else is interested, my workaround was

np.array(s.split(',')).astype(complex)

Numpy/Python version information:

Python 3.6.3
numpy 1.14.3

Activity

  1. zjpoh commented on Jul 23, 2019

    @zjpoh
    Member

    @seberg As we discussed at SciPy, I would like to try working on this. Just to double check, the following location is where I should be adding the code to parse complex values right?

    /**begin repeat
    * #fname = CFLOAT, CDOUBLE, CLONGDOUBLE,
    * OBJECT, STRING, UNICODE, VOID,
    * DATETIME, TIMEDELTA#
    */
    #define @fname@_scan NULL

    It took a while for me to find it but I think it's a good exercise. =)

    BTW, I think it would be nice to add to np.fromstring docstring on the supported dtypes.

    Thanks!

  2. seberg commented on Jul 23, 2019

    @seberg
    Member

    Yes, that is the main ting to define.

  3. seberg commented on Mar 6, 2023

    @seberg
    Member

    The linked PR impleemnted this long ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions