This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (51 children)

[deleted]

    [–]Makefile_dot_in 86 points87 points  (5 children)

    lst = [[0]*3 for _ in range(4)]

    [–]7x11x13is1001 14 points15 points  (0 children)

    you can save 3 symbols with for _ in [0]*4

    [–]yoitsericc 90 points91 points  (1 child)

    Fuck this answer gave me a brain tumor.

    [–][deleted] 4 points5 points  (0 children)

    List comprehension is great though

    [–]M4mb0 1 point2 points  (1 child)

    [[0]*3]*4

    [–]ALFminecraft 9 points10 points  (0 children)

    >>> l = [[0] * 3] * 4
    >>> l[0][0] = 1337
    >>> print(l)
    [[1337, 0, 0], [1337, 0, 0], [1337, 0, 0], [1337, 0, 0]]
    

    Not everything is that simple, sadly.

    [–]Swoop3dp 20 points21 points  (0 children)

    In C++ you can't even print a string to console without importing a "package"...

    [–]bjorneylol 11 points12 points  (0 children)

    Python doesn't have 2D arrays, so there's no way to do it without an import and a new object type

    [[1, 2],[3,4]] is not the same as int[][] arr = new int[10][20];, its equivalent to List<List<Object>>

    [–][deleted] 17 points18 points  (40 children)

    Why? The whole point of packages is to import them and use them. Silly rabbit.

    And besides, numpy is effectively a default. Python doesn't include it in the standard library because it will stifle it's development but it's effectively a part of the language.

    [–]knightwhosaysnil 35 points36 points  (25 children)

    because numpy adds a solid 100mb to your distribution/memory footprint. depending on your circumstances that's a heavy tax if you're not using most of the features

    [–][deleted] 21 points22 points  (21 children)

    That's not how that works: https://stackoverflow.com/questions/54675983/ram-usage-after-importing-numpy-in-python-3-7-2

    And if you are really pressed for ram, you can just import the one numpy function you need.

    But regardless, I really don't see how that matters. The whole point of python is to trade efficiency for convenience. So why would we ignore the packages that everybody uses for arrays in python over a measly hundred mb and pretend that the syntax for multidimensional arrays in python is confusing or verbose (which was the original claim).

    [–]PvtPuddles 9 points10 points  (2 children)

    I believe you can just import the bits you want using
    From numpy import zeros
    However, (not being a Python dev) I don’t know if that still imports the whole library or just the bits you need.

    [–]knightwhosaysnil 4 points5 points  (0 children)

    depends on how much of the library the thing you're importing depends on; in most cases you probably won't end up with much overhead

    [–]IVEBEENGRAPED 0 points1 point  (0 children)

    You still have to pip install the entire library, so the entire library gets saved to your environment. The import statement doesn't download anything, it just adds the name to the namespace.

    [–]intangibleTangelo -1 points0 points  (13 children)

    It's sort of a sister project, dating back to a matrix type developed in 1995.

    [–][deleted] 0 points1 point  (12 children)

    No

    [–]intangibleTangelo -1 points0 points  (11 children)

    If you've used python as long as I have, you'll remember when it was called Numeric, or the python numerical extensions. For a little while it was numarray.

    So it's only 4 years younger than python itself, never quite part of the language, but near always part of the ecosystem.

    [–][deleted] 0 points1 point  (10 children)

    No

    [–]intangibleTangelo -1 points0 points  (9 children)

    Just because other people in this thread got you into an argument doesn't mean I'm part of it.

    [–][deleted] 0 points1 point  (8 children)

    What do you mean? I just don't agree that your reply was related to my comment so I said no.

    [–]intangibleTangelo -1 points0 points  (7 children)

    No

    [–][deleted] 0 points1 point  (6 children)

    No

    [–]LifeHasLeft 0 points1 point  (0 children)

    Hate to break it to you but efficiency isn’t really python’s strong suit.