I am extremely new to Python and I have tried searching for answers and debugging for days but I could not solve this issue. Please help me.
Things I have tried:
numpy.array(1954.0)
Concatenate the zeros function with the converted float number: concatenate((zeros(1,142), numpy.array(1954.0)))
[It gave a ValueError: all the input arrays must have same number of dimensions]
I tried doing this instead: concatenate((zeros(1,142)), numpy.array([[1954.0]])))
and it gave a DIFFERENT ValueError message.
[ValueError: all the input array dimensions except for the concatenation axis must match exactly]
type(numpy.array(1954.0))
and it says <type 'numpy.ndarray'>
and also checked using: type((zeros(1,142))
and it says <type 'numpy.ndarray'>
. Both are of the same type, which means I should be able to concatenate but somehow it still gives me the various error messages shown in point 2 and 3. I am desperately in need of help for this.
Nicer ways to accomplish this are
a = numpy.zeros((1,143))
a[0, -1] = 1954
or
a = numpy.append(numpy.zeros((1,142)), 1954)
Mike Graham's answer's are nicer but if you insist on using concatenate, then the following will work:
x = np.zeros( (1,143))
y = np.array([[1943]])
tot = np.concatenate((x,y), axis=1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.