Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Numpy Beginner's Guide (Update)
  • Toc
  • feedback
Numpy Beginner's Guide (Update)

Numpy Beginner's Guide (Update)

By : Ivan Idris
2 (1)
close
Numpy Beginner's Guide (Update)

Numpy Beginner's Guide (Update)

2 (1)
By: Ivan Idris

Overview of this book

This book is for the scientists, engineers, programmers, or analysts looking for a high-quality, open source mathematical library. Knowledge of Python is assumed. Also, some affinity, or at least interest, in mathematics and statistics is required. However, I have provided brief explanations and pointers to learning resources.
Table of Contents (16 chapters)
close
14
C. NumPy Functions' References
15
Index

Time for action – sorting complex numbers

We will create an array of complex numbers and sort it:

  1. Generate five random numbers for the real part of the complex numbers and five numbers for the imaginary part. Seed the random generator to 42:
    np.random.seed(42)
    complex_numbers = np.random.random(5) + 1j * 
    np.random.random(5)
    print("Complex numbers\n", complex_numbers)
  2. Call the sort_complex() function to sort the complex numbers we generated in the previous step:
    print("Sorted\n", np.sort_complex(complex_numbers))

    The sorted numbers would be:

    Sorted
    [ 0.39342751+0.34955771j  0.40597665+0.77477433j  0.41516850+0.26221878j
      0.86631422+0.74612422j  0.92293095+0.81335691j]
    

What just happened?

We generated random complex numbers and sorted them using the sort_complex() function (see sortcomplex.py):

from __future__ import print_function
import numpy as np

np.random.seed(42)
complex_numbers = np.random.random(5) + 1j * np.random.random(5)
print("Complex numbers\n&quot...
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete