-1

I have 2 arrays: data = (680,) and sigma2=(680,1).

I need to do data_s= data/sigma2, but if I perform like it is, the output is data_s=(680,680), while I need to obtain data_s=(680,1).

I think I have to convert my data one-tuple with size (680,) into a pair tuple with size (680,1).

How can I do it?

Thanks in advance for the reply.

snakecharmerb
  • 28,223
  • 10
  • 51
  • 86
lorepad
  • 7
  • 1
  • 3
    These are not tuples. If they were you would get `TypeError: unsupported operand type(s) for /: 'tuple' and 'tuple'` Please, show [mre] – buran Jan 09 '21 at 11:58
  • 3
    Welcome to Stack Overflow. Your questions mentions the same values sometimes as "arrays", sometimes as "tuples". Please [edit] your question so that it's clear what data type they are. Also, please mention if you use NumPy here and if so, apply the [tag:numpy] tag. If possible, provide a [mre]. – das-g Jan 09 '21 at 12:00
  • [This might be of interest.](https://stackoverflow.com/questions/22053050/difference-between-numpy-array-shape-r-1-and-r/22074424#22074424) – Mr. T Jan 09 '21 at 12:16

1 Answers1

1

if you're referring to a shape of a NumPy array, rather than a tuple

(your provided example does not represent a tuple):

given some array x with shape (680,), you can use x[...,np.newaxis] to expand it's dimension


toy example:

x = np.empty((680,))
print(x.shape)
x = x[..., np.newaxis]
print(x.shape)

out:

(680,)
(680, 1)
Hadar Sharvit
  • 333
  • 2
  • 10