Issue
To easily calculate the dot product, I am writing a function to append a column with value 1
(concatenate at axis = 1
), this is what I did:
def function(a):
a = np.concatenate((a, np.ones(a.shape[0]), 1), axis=1)
return a
train = function(train)
test = function(test)
When I run, I get this error:
ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 3 dimension(s) and the array at index 1 has 1 dimension(s)
I understand what it means, but I don't know how to fix this, can someone help me? Thanks for your help!
Solution
You can use a temporary variable to perform the task using Python list operations like append()
:
import numpy as np
def function(a):
b = a.tolist()
for i in range(len(b)):
b[i].append(1)
return np.array(b)
train = function(np.array([[0]*4096]*2400))
print(train.shape, train)
Output:
(2400, 4097)
[[0 0 0 ... 0 0 1]
[0 0 0 ... 0 0 1]
[0 0 0 ... 0 0 1]
...
[0 0 0 ... 0 0 1]
[0 0 0 ... 0 0 1]
[0 0 0 ... 0 0 1]]
Answered By - Cardstdani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.