Hi all, What can be done if the new shape is not compatible with the original shape ? The number of columns is fixed and should be 8. One could split the original array C
C array([[ 0.00000000e+00, 1.00000000e-01], [ 4.15000000e+01, 1.00000000e-01], [ 4.16000000e+01, 1.00000000e-01], [ 6.07500000e+01, 1.00000000e-01], [ 6.08500000e+01, 1.00000000e-01], [ 8.22550000e+01, 1.00000000e-01], [ 8.23550000e+01, 1.00000000e-01], [ 9.42550000e+01, 1.00000000e-01], [ 9.43550000e+01, 1.00000000e-01], [ 9.99100000e+01, 1.00000000e-01], [ 1.00010000e+02, 1.00000000e-01], [ 1.07660000e+02, 1.00000000e-01], [ 1.07760000e+02, 1.00000000e-01], [ 1.28000000e+02, 1.00000000e-01], [ 1.28100000e+02, 1.00000000e-01]]) shape(C) (15, 2)
A = C[:8,:] A array([[ 0. , 0.1 ], [ 41.5 , 0.1 ], [ 41.6 , 0.1 ], [ 60.75 , 0.1 ], [ 60.85 , 0.1 ], [ 82.255, 0.1 ], [ 82.355, 0.1 ], [ 94.255, 0.1 ]]) A = reshape(A,(2,8)) A array([[ 0. , 0.1 , 41.5 , 0.1 , 41.6 , 0.1 , 60.75 , 0.1 ], [ 60.85 , 0.1 , 82.255, 0.1 , 82.355, 0.1 , 94.255, 0.1 ]]) B = C[8:,:] B array([[ 9.43550000e+01, 1.00000000e-01], [ 9.99100000e+01, 1.00000000e-01], [ 1.00010000e+02, 1.00000000e-01], [ 1.07660000e+02, 1.00000000e-01], [ 1.07760000e+02, 1.00000000e-01], [ 1.28000000e+02, 1.00000000e-01], [ 1.28100000e+02, 1.00000000e-01]]) B = reshape(B,(2,7)) B array([[ 9.43550000e+01, 1.00000000e-01, 9.99100000e+01, 1.00000000e-01, 1.00010000e+02, 1.00000000e-01, 1.07660000e+02], [ 1.00000000e-01, 1.07760000e+02, 1.00000000e-01, 1.28000000e+02, 1.00000000e-01, 1.28100000e+02, 1.00000000e-01]])
Nils
Can you clarify? -----הודעה מקורית----- מאת: numpy-discussion-bounces@scipy.org בשם Nils Wagner נשלח: ה 06-נובמבר-08 17:13 אל: numpy-discussion@scipy.org נושא: [Numpy-discussion] reshape Hi all, What can be done if the new shape is not compatible with the original shape ? The number of columns is fixed and should be 8. One could split the original array C
C array([[ 0.00000000e+00, 1.00000000e-01], [ 4.15000000e+01, 1.00000000e-01], [ 4.16000000e+01, 1.00000000e-01], [ 6.07500000e+01, 1.00000000e-01], [ 6.08500000e+01, 1.00000000e-01], [ 8.22550000e+01, 1.00000000e-01], [ 8.23550000e+01, 1.00000000e-01], [ 9.42550000e+01, 1.00000000e-01], [ 9.43550000e+01, 1.00000000e-01], [ 9.99100000e+01, 1.00000000e-01], [ 1.00010000e+02, 1.00000000e-01], [ 1.07660000e+02, 1.00000000e-01], [ 1.07760000e+02, 1.00000000e-01], [ 1.28000000e+02, 1.00000000e-01], [ 1.28100000e+02, 1.00000000e-01]]) shape(C) (15, 2)
A = C[:8,:] A array([[ 0. , 0.1 ], [ 41.5 , 0.1 ], [ 41.6 , 0.1 ], [ 60.75 , 0.1 ], [ 60.85 , 0.1 ], [ 82.255, 0.1 ], [ 82.355, 0.1 ], [ 94.255, 0.1 ]]) A = reshape(A,(2,8)) A array([[ 0. , 0.1 , 41.5 , 0.1 , 41.6 , 0.1 , 60.75 , 0.1 ], [ 60.85 , 0.1 , 82.255, 0.1 , 82.355, 0.1 , 94.255, 0.1 ]]) B = C[8:,:] B array([[ 9.43550000e+01, 1.00000000e-01], [ 9.99100000e+01, 1.00000000e-01], [ 1.00010000e+02, 1.00000000e-01], [ 1.07660000e+02, 1.00000000e-01], [ 1.07760000e+02, 1.00000000e-01], [ 1.28000000e+02, 1.00000000e-01], [ 1.28100000e+02, 1.00000000e-01]]) B = reshape(B,(2,7)) B array([[ 9.43550000e+01, 1.00000000e-01, 9.99100000e+01, 1.00000000e-01, 1.00010000e+02, 1.00000000e-01, 1.07660000e+02], [ 1.00000000e-01, 1.07760000e+02, 1.00000000e-01, 1.28000000e+02, 1.00000000e-01, 1.28100000e+02, 1.00000000e-01]])
Nils _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
On Thu, 6 Nov 2008 19:47:19 +0200
"Nadav Horesh"
Can you clarify?
I have an array with a number of rows (nrows) and two columns. The first column entries correspond to x_i, the second column contains the corresponding values y_i = f(x_i) That array should be written to a file where each line consists 4 pairs (x_i, y_i=f(x_i)) except the last line if nrows/8 is not an integer. HTH, Nils
cc = C.ravel()
lines_list = cc[i:i+8] for i in range(1, len(cc), 8)]
Nadav
-----הודעה מקורית-----
מאת: numpy-discussion-bounces@scipy.org בשם Nils Wagner
נשלח: ה 06-נובמבר-08 20:59
אל: Discussion of Numerical Python
נושא: Re: [Numpy-discussion] reshape
On Thu, 6 Nov 2008 19:47:19 +0200
"Nadav Horesh"
Can you clarify?
I have an array with a number of rows (nrows) and two columns. The first column entries correspond to x_i, the second column contains the corresponding values y_i = f(x_i) That array should be written to a file where each line consists 4 pairs (x_i, y_i=f(x_i)) except the last line if nrows/8 is not an integer. HTH, Nils _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
A correction:
lines_list = [cc[i:i+8] for i in range(1, len(cc), 8)]
Nadav
-----הודעה מקורית-----
מאת: numpy-discussion-bounces@scipy.org בשם Nadav Horesh
נשלח: ה 06-נובמבר-08 21:43
אל: Discussion of Numerical Python
נושא: RE: [Numpy-discussion] reshape
cc = C.ravel()
lines_list = cc[i:i+8] for i in range(1, len(cc), 8)]
Nadav
-----הודעה מקורית-----
מאת: numpy-discussion-bounces@scipy.org בשם Nils Wagner
נשלח: ה 06-נובמבר-08 20:59
אל: Discussion of Numerical Python
נושא: Re: [Numpy-discussion] reshape
On Thu, 6 Nov 2008 19:47:19 +0200
"Nadav Horesh"
Can you clarify?
I have an array with a number of rows (nrows) and two columns. The first column entries correspond to x_i, the second column contains the corresponding values y_i = f(x_i) That array should be written to a file where each line consists 4 pairs (x_i, y_i=f(x_i)) except the last line if nrows/8 is not an integer. HTH, Nils _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
On Thu, 6 Nov 2008 21:50:52 +0200
"Nadav Horesh"
A correction:
lines_list = [cc[i:i+8] for i in range(1, len(cc), 8)]
Nadav
Hi Nadav, Thank you very much. My next question; How can I save lines_list to a file with the following so called small field format (NASTRAN). Each row consists of ten fields of eight characters each. Field 1 should be empty in my application. Field 10 is used only for optional continuation information when applicable. 12345678123456781234567812345678123456781234567812345678123456781234567812345678 xxxxxxxxyyyyyyyyzzzzzzzz........ Cheers, Nils
I can not figure out the format specifications, but the following function might be a good starting point:
def lst_to_file(lst, filename, fmt='%08d'):
'''
lst: list of arrays to write
filename: output file name
fmt: The format of single item
'''
str_lst = []
for l in lst:
format = len(l)*fmt + '\n'
str_lst.append(format % tuple(l))
open(filename, 'w').write(''.join(str_lst))
-----הודעה מקורית-----
מאת: numpy-discussion-bounces@scipy.org בשם Nils Wagner
נשלח: ה 06-נובמבר-08 22:07
אל: Discussion of Numerical Python
נושא: Re: [Numpy-discussion] reshape
On Thu, 6 Nov 2008 21:50:52 +0200
"Nadav Horesh"
A correction:
lines_list = [cc[i:i+8] for i in range(1, len(cc), 8)]
Nadav
Hi Nadav, Thank you very much. My next question; How can I save lines_list to a file with the following so called small field format (NASTRAN). Each row consists of ten fields of eight characters each. Field 1 should be empty in my application. Field 10 is used only for optional continuation information when applicable. 12345678123456781234567812345678123456781234567812345678123456781234567812345678 xxxxxxxxyyyyyyyyzzzzzzzz........ Cheers, Nils _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Nadav Horesh
-
Nils Wagner