numpy array rows and columns

Thread Solved

Join Date: Nov 2009
Posts: 2
Reputation: Chromana is an unknown quantity at this point 
Solved Threads: 0
Chromana Chromana is offline Offline
Newbie Poster

numpy array rows and columns

 
0
  #1
19 Days Ago
Hey. I'm importing an array in a text file via array=numpy.loadtxt("testdata.txt") .
Is there an easy way to count the number of rows and columns? Maybe something like x=numpy.countrow(array) ?
I've had a look around and couldn't find anything suitable.
Thanks, Alex
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,985
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 927
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite
 
0
  #2
18 Days Ago
Use numpy shape ...
  1. import numpy as np
  2.  
  3. # create a 3 by 5 array of integer zeroes
  4. z = np.zeros([3, 5], int)
  5. print( z )
  6. """
  7. [[0 0 0 0 0]
  8. [0 0 0 0 0]
  9. [0 0 0 0 0]]
  10. """
  11.  
  12. # check the shape
  13. print( "shape --> %d rows x %d columns" % z.shape )
  14. """
  15. [[0 0 0 0 0]
  16. [0 0 0 0 0]
  17. [0 0 0 0 0]]
  18. shape --> 3 rows x 5 columns
  19. """
Last edited by vegaseat; 18 Days Ago at 7:05 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 2
Reputation: Chromana is an unknown quantity at this point 
Solved Threads: 0
Chromana Chromana is offline Offline
Newbie Poster
 
0
  #3
18 Days Ago
I found out from a friend.
  1. x = array.shape[0] # sets x as the number of rows
  2. y = array.shape[1] # sets y as the number of columns
Thanks for your input anyway!
Last edited by Chromana; 18 Days Ago at 7:54 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC