How do I input a square of odd numbers between 1 and 99?

Response to: https://www.quora.com/unanswered/How-do-I-input-a-square-of-odd-numbers-between-1-and-99

import sys
import os
import numpy as np

#get range of numbers 1 to 99
number = np.arange(100)
#create an empty list
numberSquares = []

print("This is a list of your odd numbers in range 1 to 99:")
for n in np.nditer(number.T):
     if n % 2 != 0:
        print(n) 
        exponent = n*n 
        numberSquares.append(exponent)

print("This is a list of the squares of your odd numbers in range 1 to 99:")
for a in numberSquares:
    print(a)

print("This is a list of the squares of the numpy number array: ")
print(np.square(number[1::2]))

print("This is the sum of the squares of the numpy number array: ")
print(np.sum(np.square(number[1::2])))

print("This is the square of the sum of the number numpy array:")
print(np.square(np.sum(number[1::2])))


 

%d bloggers like this: