Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python numpy how to empty array cycle

In [210]: %%timeit
   .....: l = []
   .....: for i in xrange(1000):
   .....:     l.append([3*i+1,3*i+2,3*i+3])
   .....: l = np.asarray(l)
   .....: 
1000 loops, best of 3: 1.18 ms per loop

In [211]: %%timeit
   .....: a = np.empty((0,3), int)
   .....: for i in xrange(1000):
   .....:     a = np.append(a, 3*i+np.array([[1,2,3]]), 0)
   .....: 
100 loops, best of 3: 18.5 ms per loop

In [214]: np.allclose(a, l)
Out[214]: True
Comment

PREVIOUS NEXT
Code Example
Python :: python isdigit 
Python :: convert series to dataframe pandas 
Python :: net way to print 2d array 
Python :: strip plot (normal) 
Python :: how to download a pip package with python and os 
Python :: remove key from dictionary python 
Python :: django run command from code 
Python :: python delete key if exists 
Python :: python django login register 
Python :: remove rows from dataframe 
Python :: Print statement with multiple variables 
Python :: Tree Traversals inorder,preorder and postorder 
Python :: dataframe select row by index value 
Python :: lower method in python 
Python :: pandas fillna multiple columns 
Python :: python get file ending 
Python :: removing stop words from the text 
Python :: python list append() 
Python :: django password hashing 
Python :: string manipulation in python 
Python :: Converting 12 hour clock time to 24 hour clock time 
Python :: loop for python 
Python :: for loop in python 
Python :: Python Pandas: Create new column out of other columns where value is not null 
Python :: cross validation sklearn 
Python :: Python NumPy split Function Syntax 
Python :: get nth character of string python 
Python :: print all objects in list python 
Python :: all string methods in python 
Python :: jupiter lab 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =