0

So I am teaching myself Python and I recently stumbled upon these kinds of code: plt.scatter(X_pca_2c[:,0], X_pca_2c[:,1], c=iris.target, alpha=0.8, edgecolors='none') and np.array(tf_vect.get_feature_names())[tsvd_2c.components_[20].argsort ()[-10:][::-1]]

The functions are too advanced for me at this stage, I know, but I am learning Python arrays now and I wonder how do I interpret the [:,0], [:,1],[-10:][::-1] here?

I stumbled across such notations a lot and I want to get my understanding right. I thought it was a simple index at first, but then I realize there is such a thing as [::-1] too. Anybody kindly explain the logic behind them? Thanks a lot!!

user71812
  • 457
  • 2
  • 4
  • 19
  • Half of those are not Python, per se, they are numpy. – Stephen Rauch Jul 12 '19 at 04:40
  • Stack Overflow is not a tutorial site. Numpy has great documentation, and once you're ready for it, check out https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html. That page has more than you want to know about expressions just like the ones you are interested in. – Mad Physicist Jul 12 '19 at 04:42
  • @Stephen. True, but they are bundled by Python into Python objects before being sent to numpy for interpretation. – Mad Physicist Jul 12 '19 at 04:43
  • @MadPhysicist, fair enough, so we can either close as too broad, or close with a dupe of the easier half of the too broad... – Stephen Rauch Jul 12 '19 at 04:46

0 Answers0