1

I'd like to use numpy to make my program faster. The only part I want to use is string arrays. When I do

import numpy

it takes about 5 seconds to loop numpy, which is more time than the speedup I was looking to get for my normal program.

Is there a way to only load the string array part of numpy?

Superdooperhero
  • 7,584
  • 19
  • 83
  • 138

2 Answers2

0

You can try:

from numpy import array

This should not be any faster as both ways import the entire module. I have no idea why it is in your case.

msvalkon
  • 11,887
  • 2
  • 42
  • 38
  • 1
    This still imports `numpy`, from what I remember. – Blender Mar 09 '13 at 21:28
  • 1
    I don't think this will help at all. It still imports everything from `numpy/dir/__init__.py`. That just controls what goes into your local namespace. – mgilson Mar 09 '13 at 21:28
  • Thanks, that takes it down to loading in 0.2 seconds – Superdooperhero Mar 09 '13 at 21:30
  • @Blender,@mgilson you are both correct, however the OP reports a faster loading time. I've added a link to an SO answer with a deeper analysis of importing using the `dis` module. @Superdooperhero - When do you import? everything in this sounds absolutely strange. – msvalkon Mar 09 '13 at 22:03
  • @msvalkon -- That doesn't say anything about how long it takes to do the *import* though. Only about efficiency of skipping an attribute access every time... – mgilson Mar 09 '13 at 22:13
-2

I think that very not important if you import everything or just partial. What matters are efficient algorithms used and how you run the application. first, take a look on Python speed. Also try to use JIT compiler, like PyPy.

Mihai8
  • 3,113
  • 1
  • 21
  • 31
  • 1
    PyPy doesn't support Numpy yet. – Blender Mar 09 '13 at 22:06
  • It seems to supported it, see http://morepypy.blogspot.ro/2012/11/numpy-status-update-5.html and http://stackoverflow.com/questions/5883885/using-numpy-with-pypy – Mihai8 Mar 09 '13 at 22:10