1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Formatting numpy arrays with black

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am using vscode along with black as a formatter. I don't like how it formats numpy arrays and how it is effected by line length, for example

    F = np.array([[1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1]])


    versus

    F = np.array(
    [
    [1, 1, 0.5, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 1, 1, 0.5, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 1, 1, 0.5],
    ]
    )


    For readability I prefer the latter, but black formats the latter style when the former style would violate the line length.

    Is there a way to customize black to prefer formatting the latter style without changing the line length parameter.

    I am open to other formatters, I am just using black because it interfaces nice with flake8. My line length is set to 88.

    Continue reading...

Compartilhe esta Página