1

I have a numpy ndarray with 6 values in 1 dim. These 6 values represent a point in 6 dimensions. How do I convert it in numpy to get a 6d array?

Backstory: I need this 6d layout for my neural network. The training happend with 6d data. For making predicitons I fail to reshape the data.

quibelua
  • 13
  • 3
  • What is the shape of your array and what is the expected output shape? – Dani Mesejo Jan 01 '19 at 14:13
  • https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.reshape.html – Dani Mesejo Jan 01 '19 at 14:14
  • Provide a [mcve] please. It is obvious to me what you want but that cannot be said for everyone and all future visitors without at least a coherent example. – cs95 Jan 01 '19 at 14:16
  • import numpy as np x = np.array([1,2,3,4,5,6]) x.ndim # is 1 what I need is: shape (6,) – quibelua Jan 01 '19 at 14:23
  • I don't think you want a `6d` array. More likely there's confusion over shapes, (6,), (1,6), and (6,1). – hpaulj Jan 01 '19 at 14:39
  • Got it! np.reshape(x, (1,-1)) did the trick. This reshaped to (6,1) which was accepted. I got confused by the dimensionality aspect from the thing im trying. Thanks everyone :) – quibelua Jan 01 '19 at 14:45

2 Answers2

1

Here, is the solution of your requirement which you mentioned above in comments, but important thing to understand is (6,) is not a 6-dimensional array. It's an array of shape (6, ) is 1-dimensional and consists of 6 elements.

import numpy as np 
x = np.array([1,2,3,4,5,6]) 
x = np.reshape(a, (6,))
print(x.shape)

Output:

(6,)

print(x)

Output:

[1 2 3 4 5 6]
Abdur Rehman
  • 1,071
  • 1
  • 9
  • 15
0

You can use numpy.reshape

import numpy as np
# for example my numpy array having 6 elements is [1,2,3,4,5,6]
a = np.array([1,2,3,4,5,6])
# array([1, 2, 3, 4,5,6])
b = np.reshape(a, (-1,1))
Aman Raparia
  • 494
  • 1
  • 5
  • 13