NumPy: Display all the dates for the month of March, 2017
NumPy DateTime: Exercise-1 with Solution
Write a NumPy program to display all the dates for the month of March, 2017.
Sample Solution:-
Python Code:
import numpy as np
print("March, 2017")
print(np.arange('2017-03', '2017-04', dtype='datetime64[D]'))
Sample Output:
March, 2017 ['2017-03-01' '2017-03-02' '2017-03-03' '2017-03-04' '2017-03-05' '2017-03-06' '2017-03-07' '2017-03-08' '2017-03-09' '2017-03-10' '2017-03-11' '2017-03-12' '2017-03-13' '2017-03-14' '2017-03-15' '2017-03-16' '2017-03-17' '2017-03-18' '2017-03-19' '2017-03-20' '2017-03-21' '2017-03-22' '2017-03-23' '2017-03-24' '2017-03-25' '2017-03-26' '2017-03-27' '2017-03-28' '2017-03-29' '2017-03-30' '2017-03-31']
Pictorial Presentation:
Python-Numpy Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:NumPy DateTime Exercises Home.
Next: Write a NumPy program to get the dates of yesterday, today and tomorrow.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Python: Tips of the Day
Decompose a collection:
Assume we have a function that returns a tuple of two values and we want to assign each value to a separate variable. One way is to use indexing as below:
abc = (5, 10) x = abc[0] y = abc[1] print(x, y)
Output:
5 10
There is a better option that allows us to do the same operation in one line.
x, y = abc print(x, y)
Output:
5 10
It can be extended to a tuple with more than 2 values or some other data structures such as lists or sets.
x, y, z = {1, 2, 3} print(x, y, z) x, y, z = ['a', 'b', 'c'] print(x, y, z)
Output:
1 2 3 a b c
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises