944,129 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 3627
  • Python RSS
Nov 7th, 2009
0

numpy array rows and columns

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Chromana is offline Offline
2 posts
since Nov 2009
Nov 8th, 2009
0
Re: numpy array rows and columns
Use numpy shape ...
Python Syntax (Toggle Plain Text)
  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; Nov 8th, 2009 at 7:05 pm.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Nov 8th, 2009
1
Re: numpy array rows and columns
I found out from a friend.
Python Syntax (Toggle Plain Text)
  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; Nov 8th, 2009 at 7:54 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Chromana is offline Offline
2 posts
since Nov 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Drawing Circles?
Next Thread in Python Forum Timeline: Help with my Blackjack Program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC