import numpy
my_array = numpy.array([])
a=int(input("Size of array:"))
for i in range(a):
x=float(input("Element:"))
numpy.append(x)
print(numpy.floor(my_array))
Asked
Active
Viewed 5.9k times
3

Rakesh
- 81,458
- 17
- 76
- 113

Kaushal Raj
- 63
- 1
- 2
- 7
-
What is your question exactly? – Apr 02 '18 at 07:49
-
I am trying to solve hackerrank.com question.Here is the link https://www.hackerrank.com/challenges/floor-ceil-and-rint/forum .I have found a way to input but the output format is wrong.check my code. import numpy as np A = np.array(input().split(' '),float) print(np.floor(A)) print(np.ceil(A)) print(np.rint(A)) – Kaushal Raj Apr 02 '18 at 08:07
-
1Please update your post with a proper question/problem and code formatting, so that others may benefit from reading it. – MPA Apr 02 '18 at 08:19
-
The question asks how can one read an input from the user to enter the "size of the array" and other parameters. This has been asked and answered before here: https://stackoverflow.com/a/38670261/53720. Please if you have other problems be more specific about what sort of error you are dealing with. – brutuscat Aug 19 '20 at 18:22
-
Does this answer your question? [How do you read from stdin?](https://stackoverflow.com/questions/1450393/how-do-you-read-from-stdin) – brutuscat Aug 19 '20 at 18:23
7 Answers
5
n, m = map(int, input().split()) # taking number of rows and column
array = numpy.array([input().strip().split() for _ in range(n)], int)

ayesha kaleem
- 77
- 2
- 7
3
Please try this
from numpy import *
arr = array([])
n = int(input("Enter the number of values you want: "))
for i in range(n):
v = input("Element: ")
arr = append(arr, v)
print(arr)

Vedant Matanhelia
- 31
- 2
2
numpy.append
does not work like this, the array is missing to append to.
Better, build a normal list and convert it to a numpy array afterwards:
import numpy
my_array = []
a = int(input("Size of array:"))
for i in range(a):
my_array.append(float(input("Element:")))
my_array = numpy.array(my_array)
print(numpy.floor(my_array))

Daniel
- 42,087
- 4
- 55
- 81
2
You take input as list and then put it into a numpy array.
import numpy
op= list(map(int,input().split()))
op = numpy.asarray(op)

Vineet Kumar Gupta
- 357
- 3
- 4
1
Using List Comprehension
a=int(input()
b=[int(j) for j in input().split()]
print(np.array(b))

sree
- 11
- 2
0
You can initialise a list of length 'a' and then can replace its element with input elements:
import numpy
a=int(input("Size of array:"))
my_array = numpy.empty(a)
for i in range(len(my_array)):
x=float(input("Element:"))
my_array[i]=x
print(numpy.floor(my_array))
0
please try this
from numpy import *
n=int(input("Enter Size of array"))
arr=zeros(n,dtype=int)
for i in range(n):
x=int(input("Enter the value"))
arr[i]=x
print(arr)