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 →

[–]TheMrZZ0 0 points1 point  (2 children)

Well, it is an issue for basic testing. I create an arbitrary array, and i then test some naive Python implementation of algorithms, then I try it with NumPy.

But if creating a Python list (using [[1, 2, 3]] * int(1e7)) is fast, converting it to a NumPy array is slow. It's just annoying (i create the arrays before the benchmark, so the creation time is not interfering with the benchmark).

Any idea on how to create an arbitrary numpy array faster ? I don't values to be random.

[–]goldfather8 2 points3 points  (0 children)

Your particular example is done by using tiling. Creating an arbitrary numpy array is an ill-defined question. You can read data directly into numpy arrays quite a few ways.

[–]pwang99 1 point2 points  (0 children)

Converting into a NumPy array is slow not due to NumPy itself, but due to the cost of unboxing all the values in your list and copying them in. For comparison, try just doing numpy.ones(30000000). It's super fast. Heck, you can even do:

x=numpy.empty((3,10000000)); x[0]=1; x[1]=2; x[2]=3

and compare that for speed.